- 65
- 6
Делал печь по
1.Хотелось бы сделать крафты через OreDictionary, чтобы не только мою медь, но и медь, допустим из индастриала моя печь тоже принимала...
2.Как указать несколько слитков, т.е. бронза = 3 меди + 1 олово.А у меня печь принимает 1 медь + 1 олово и выдаёт 4 бронзы.
Заранее спасибо!
2.Как указать несколько слитков, т.е. бронза = 3 меди + 1 олово.А у меня печь принимает 1 медь + 1 олово и выдаёт 4 бронзы.
Заранее спасибо!
Класс блока:
package ru.mrtenfan.metalfever.blocks;
import java.util.Random;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import ru.mrtenfan.metalfever.MetalFeverMain;
import ru.mrtenfan.metalfever.init.MFBlocks;
import ru.mrtenfan.metalfever.init.MFOther;
import ru.mrtenfan.metalfever.tileentity.TileEntityAlloyFurnace;
public class AlloyFurnace extends BlockContainer {
private Random rand;
private final boolean isActive;
private static boolean keepInventory = false;
private String texPath= "metalfever:";
@SideOnly(Side.CLIENT)
protected IIcon BlockIconFront;
protected IIcon BlockIconSide;
protected IIcon BlockIconTop;
protected IIcon BlockIconDown;
@SideOnly(Side.CLIENT)
private IIcon iconFront;
public AlloyFurnace(Material mat, String name, float hard, float resist, String tool, int lvl, boolean work) {
super(mat);
if (work == false)
this.setCreativeTab(MFOther.TabMetalFeverMain);
else
this.setLightLevel(0.625F);
this.setHardness(hard);
this.setResistance(resist);
this.setHarvestLevel(tool, lvl);
this.setBlockName(name);
rand = new Random();
isActive = work;
}
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister par1IconRegister)
{
// Регистрируем путь до png-текстур для разных сторон блока
BlockIconFront = par1IconRegister.registerIcon(this.isActive ? texPath + "alloy_furnace_on" : texPath + "alloy_furnace_off");
BlockIconSide = par1IconRegister.registerIcon(texPath + "alloy_furnace_side");
BlockIconTop = par1IconRegister.registerIcon(texPath + "alloy_furnace_top");
BlockIconDown = par1IconRegister.registerIcon(texPath + "alloy_furnace_top2");
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta)
{
if (side == 0)
return BlockIconDown;
if (side == 1)
return BlockIconTop;
if (meta == 2 && side == 2)
return BlockIconFront;
if (meta == 3 && side == 5)
return BlockIconFront;
if (meta == 0 && side == 3)
return BlockIconFront;
if (meta == 1 && side == 4)
return BlockIconFront;
return BlockIconSide;
}
// Этот метод вызывается когда блок ставится кем-то
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityPlayer, ItemStack itemStack)
{
int i = MathHelper.floor_double((double)(entityPlayer.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
world.setBlockMetadataWithNotify(x, y, z, i, 2);
}
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return true;
}else if (!player.isSneaking()) {
TileEntityAlloyFurnace entity = (TileEntityAlloyFurnace) world.getTileEntity(x, y, z);
if (entity != null) {
FMLNetworkHandler.openGui(player, MetalFeverMain.instance, MFBlocks.GUI_ID_alloy_furnace, world, x, y, z);
}
return true;
} else {
return false;
}
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
return new TileEntityAlloyFurnace();
}
//Update 1.1.0
public static void updateBlockState(boolean isAlloying, World world, int xCoord, int yCoord, int zCoord) {
int i = world.getBlockMetadata(xCoord, yCoord, zCoord);
TileEntity entity = world.getTileEntity(xCoord, yCoord, zCoord);
keepInventory = true;
if (isAlloying)
world.setBlock(xCoord, yCoord, zCoord, MFBlocks.alloy_furnace_active);
else
world.setBlock(xCoord, yCoord, zCoord, MFBlocks.alloy_furnace_idle);
keepInventory = false;
world.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, i, 2);
if (entity != null) {
entity.validate();
world.setTileEntity(xCoord, yCoord, zCoord, entity);
}
}
}
TileEntity:
package ru.mrtenfan.metalfever.tileentity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import ru.mrtenfan.metalfever.ConfigFile;
import ru.mrtenfan.metalfever.blocks.AlloyFurnace;
import ru.mrtenfan.metalfever.crafting.AlloyFurnaceRecipes;
import ru.mrtenfan.metalfever.init.MFItems;
public class TileEntityAlloyFurnace extends TileEntity implements ISidedInventory {
private String localyzedName;
private ItemStack slots[];
public int dualCookTime;
public int dualPower;
public static final int maxPower = 241;
public static final int alloyingSpeed = 240;
private static final int[] slots_top = new int[] {0, 1};
private static final int[] slots_bottom = new int[] {3, 4};
private static final int[] slots_side = new int[] {2};
public TileEntityAlloyFurnace() {
slots = new ItemStack[5];
}
@Override
public int getSizeInventory() {
return slots.length;
}
@Override
public ItemStack getStackInSlot(int i) {
return slots[i];
}
@Override
public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
return null;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemStack) {
slots[i] = itemStack;
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit())
itemStack.stackSize = getInventoryStackLimit();
}
@Override
public String getInventoryName() {
return this.hasCustomInventoryName() ? this.localyzedName : "container.alloyFurnace";
}
public int[] getAccessibleSlotsFromSide(int side) {
return side == 0 ? slots_bottom : (side == 1 ? slots_top : slots_side);
}
@Override
public boolean hasCustomInventoryName() {
return this.localyzedName != null && this.localyzedName.length() > 0;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return worldObj.getTileEntity(xCoord, yCoord, zCoord) != this ? false : player.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64.0D;
}
public void openInventory() {}
public void closeInventory() {}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemStack) {
return i == 2 ? false : (i == 1 ? hasItemPower(itemStack) : true);
}
public boolean hasItemPower(ItemStack itemStack) {
return getItemPower(itemStack) > 0;
}
private static int getItemPower(ItemStack itemStack) {
if (itemStack == null)
return 0;
else {
Item item = itemStack.getItem();
if (item == Items.coal)
return 240;
}
return 0;
}
public ItemStack decrStackSize(int i, int j) {
if (slots[i] != null) {
if (slots[i].stackSize <= j ) {
ItemStack itemStack = slots[i];
slots[i] = null;
return itemStack;
}
ItemStack itemStack1 = slots[i].splitStack(j);
if (slots[i].stackSize == 0)
slots[i] = null;
return itemStack1;
}else
return null;
}
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
NBTTagList list = nbt.getTagList("Items", 10);
slots = new ItemStack[getSizeInventory()];
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound nbt1 = (NBTTagCompound)list.getCompoundTagAt(i);
byte b0 = nbt1.getByte("Slot");
if (b0 >= 0 && b0 < slots.length) {
slots[b0] = ItemStack.loadItemStackFromNBT(nbt1);
}
}
dualPower = nbt.getShort("PowerTime");
dualCookTime = nbt.getShort("CookTime");
}
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setShort("PowerTime", (short)dualPower);
nbt.setShort("CookTime", (short)dualCookTime);
NBTTagList list = new NBTTagList();
for (int i = 0; i < slots.length; i++ ) {
if (slots[i] != null) {
NBTTagCompound nbt1 = new NBTTagCompound();
nbt1.setByte("Slot", (byte)i);
slots[i].writeToNBT(nbt1);
list.appendTag(nbt1);
}
}
nbt.setTag("Items", list);
}
@Override
public boolean canInsertItem(int var1, ItemStack itemStack, int var3) {
return this.isItemValidForSlot(var1, itemStack);
}
@Override
public boolean canExtractItem(int var1, ItemStack itemStack, int var3) {
return var3 != 0 || var1 != 1 || itemStack.getItem() == MFItems.slag;
}
public int getAlloyProgressScaled(int i) {
return (dualCookTime * i) / alloyingSpeed;
}
public int getPowerRemainingScaled(int i) {
return (dualPower * i) / maxPower;
}
private boolean canAlloy() {
if (slots[0] == null || slots[1] == null)
return false;
ItemStack itemStack = AlloyFurnaceRecipes.getAlloyingResult(slots[0].getItem(), slots[1].getItem());
if (itemStack == null) {
return false;
}
if (slots[3] == null) {
return true;
}
if (!slots[3].isItemEqual(itemStack)) {
return false;
}
if (slots[3].stackSize < getInventoryStackLimit() && slots[3].stackSize < slots[3].getMaxStackSize())
return true;
else
return slots[3].stackSize < itemStack.getMaxStackSize();
}
private void alloyItem() {
if (canAlloy()) {
ItemStack itemStack = AlloyFurnaceRecipes.getAlloyingResult(slots[0].getItem(), slots[1].getItem());
ItemStack slag = new ItemStack(MFItems.slag);
if (slots[3] == null)
slots[3] = itemStack.copy();
else if (slots[3].isItemEqual(itemStack))
slots[3].stackSize += itemStack.stackSize;
if (slots[4] == null)
slots[4] = slag.copy();
else if (slots[4].isItemEqual(slag))
slots[4].stackSize += slag.stackSize;
for (int i = 0; i < 2; i++) {
if (slots[i].stackSize <= 0)
slots[i] = new ItemStack(slots[i].getItem().setFull3D());
else
slots[i].stackSize--;
if (slots[i].stackSize <= 0)
slots[i] = null;
}
}
}
public boolean hasPower() {
return dualPower > 0;
}
public boolean isAlloying() {
return this.dualCookTime > 0;
}
public void updateEntity() {
boolean flag = this.hasPower();
boolean flag1 = false;
if(hasPower() && this.isAlloying())
this.dualPower--;
if(!worldObj.isRemote) {
if (this.hasItemPower(this.slots[2]) && this.dualPower < (this.maxPower - this.getItemPower(this.slots[2]))) {
this.dualPower += getItemPower(this.slots[2]);
if(this.slots[2] != null) {
flag1 = true;
this.slots[2].stackSize--;
if(this.slots[2].stackSize == 0)
this.slots[2] = this.slots[2].getItem().getContainerItem(this.slots[2]);
}
}
if (hasPower() && canAlloy()) {
dualCookTime++;
if(this.dualCookTime == this.alloyingSpeed) {
this.dualCookTime = 0;
this.alloyItem();
flag1 = true;
}
}else {
dualCookTime = 0;
}
if (flag != this.hasPower()) {
flag1 = true;
AlloyFurnace.updateBlockState(this.isAlloying(), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
}
}
if (flag1) {
this.markDirty();
}
}
}
Класс рецептов:
package ru.mrtenfan.metalfever.crafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import ru.mrtenfan.metalfever.init.MFItems;
public class AlloyFurnaceRecipes {
public AlloyFurnaceRecipes() {
}
public static ItemStack getAlloyingResult(Item item, Item item2) {
return getOutput(item, item2);
}
public static ItemStack getOutput(Item item, Item item2) {
if (item == new ItemStack(MFItems.metals_ingot, 3, 2).getItem() && item2 == new ItemStack(MFItems.metals_ingot, 1, 6).getItem() || item == new ItemStack(MFItems.metals_ingot, 1, 6).getItem() && item2 == new ItemStack(MFItems.metals_ingot, 3, 2).getItem()) {
return new ItemStack(MFItems.alloys_ingot, 4, 0);
}
return null;
}
}