
Messorix
Members-
Posts
60 -
Joined
-
Last visited
Everything posted by Messorix
-
Sure ModBlock (parent of all type of custom blocks) BlockMachine (parent of all blocks with processing like furnace and stuff) BlockFluxGrinder (the grinder itself)
-
Well... Didn't realize that you meant that My bad The functionality is based around it making the block in question work like a machine with a way of processing items. I'm making the flux grinder first, but flux furnace will be next for example. A bit similar to Thermal expansions pulverizer and redstone furnace.
-
TileEntityFluxGrinder is the flux grinder's entity class (since it is a custom 3d model) ModTileEntity is the parent class where most of the logic of it is stored, so that other entity classes can be as clean as possible without losing the same functionality. Basic coding design afaik
-
Which one? The ModTileEntity or the TileEntityFluxGrinder?
-
has quite a good set of tutorials going for 1.9 (some also for 1.10.x), but I'm not sure if minecarts will be the same way as normal entities. Worth checking out though
-
The dumb part is that in the tutorial (its a video) it works instantly (texture bugs put aside )
-
Line 65: Line 38: I just followed the tutorial on that part
-
After fixing that, it still crashed but with a different log: As you can see, it seems very familiar... burnTimeRemaining has to be the cause, but I'm not sure in what way
-
Oh god I didn't even see that one. I guess that one has priority now
-
I have changed the way I set the fields to their values in my TileEntityFluxGrinder class (see below) package com.messy.core.tileentities; import com.messy.core.crafting.FluxGrinderRecipes; import net.minecraft.item.ItemStack; public class TileEntityFluxGrinder extends ModTileEntity { private static boolean setupDone = false; public static final int fuel_slots = 1; public static final int input_slots = 2; public static final int output_slots = 1; protected ItemStack[] itemStacks = new ItemStack[total_slots]; public static ItemStack getProcessingResultForItem(ItemStack stack){ return ModTileEntity.getProcessingResultForItem(FluxGrinderRecipes.instance().getGrindingResult(stack)); } @Override public String getName() { return "container.tile_entity_flux_grinder.name"; } public int numberOfBurningFuelSlots() { if (!setupDone) { total_slots = fuel_slots + input_slots + output_slots; first_input_slot = first_fuel_slot + input_slots; first_output_slot = first_input_slot + output_slots; burnTimeInitial = new int[fuel_slots]; burnTimeRemaining = new int[fuel_slots]; setupDone = true; } return super.numberOfBurningFuelSlots(); } public void setCustomInventoryName(String displayName) { } } Now whenever I open the Flux grinder, the whole thing just crashes: I guess you could call this progress
-
I think I have it partly fixed now (not the alignment thought) Quick question though... are tile entities supposed to be common side or client only side?
-
public class TileEntityFluxGrinder extends ModTileEntity { public static final int fuel_slots = 1; public static final int input_slots = 2; public static final int output_slots = 1; Are you sure?
-
package com.messy.core.tileentities; import com.messy.core.crafting.FluxGrinderRecipes; import net.minecraft.item.ItemStack; public class TileEntityFluxGrinder extends ModTileEntity { public static final int fuel_slots = 1; public static final int input_slots = 2; public static final int output_slots = 1; public int[] burnTimeRemaining = new int[fuel_slots]; public int[] burnTimeInitial = new int[fuel_slots]; public static ItemStack getProcessingResultForItem(ItemStack stack){ return ModTileEntity.getProcessingResultForItem(FluxGrinderRecipes.instance().getGrindingResult(stack)); } @Override public String getName() { return "container.tile_entity_flux_grinder.name"; } public double fractionOfFuelRemaining(int fuelSlot) { return super.fractionOfFuelRemaining(fuelSlot, burnTimeInitial); } public void setCustomInventoryName(String displayName) { } } package com.messy.core.tileentities; import java.util.Arrays; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagIntArray; import net.minecraft.nbt.NBTTagList; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.util.ITickable; import net.minecraft.util.math.MathHelper; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.EnumSkyBlock; public class ModTileEntity extends TileEntity implements IInventory, ITickable { public static final int fuel_slots = 0; public static final int input_slots = 0; public static final int output_slots = 0; public static final int total_slots = fuel_slots + input_slots + output_slots; public static final int first_fuel_slot = 0; public static final int first_input_slot = first_fuel_slot + input_slots; public static final int first_output_slot = first_input_slot + output_slots; protected ItemStack[] itemStacks = new ItemStack[total_slots]; protected int[] burnTimeRemaining; protected int[] burnTimeInitial; protected short processTime; protected static final short working_time_for_completion = 200; protected int cachedNumberOfBurningSlots = -1; public double fractionOfFuelRemaining(int fuelSlot, int[] burnTimeInitial) { double fraction; this.burnTimeInitial = burnTimeInitial; if (this.burnTimeInitial[fuelSlot] <= 0) { fraction = 0; } else { fraction = burnTimeRemaining[fuelSlot] / (double) burnTimeInitial[fuelSlot]; } return MathHelper.clamp_double(fraction, 0.0, 1.0); } public int secondsOfFuelRemaining(int fuelSlot) { if (burnTimeRemaining[fuelSlot] <= 0) { return 0; } return burnTimeRemaining[fuelSlot] / 20; } public int numberOfBurningFuelSlots() { int burningCount = 0; for (int burnTime : burnTimeRemaining) { if (burnTime > 0) { ++burningCount; } } return burningCount; } public double fractionOfProcessingTimeComplete() { double fraction = processTime / (double) working_time_for_completion; return MathHelper.clamp_double(fraction, 0.0, 1.0); } protected int burnFuel() { int burningCount = 0; boolean inventorychanged = false; for (int i = 0; i < fuel_slots; i++) { int fuelSlotNumber = i + first_fuel_slot; if (burnTimeRemaining[i] > 0) { --burnTimeRemaining[i]; ++burningCount; } if (burnTimeRemaining[i] == 0) { if (itemStacks[fuelSlotNumber] != null && getItemBurnTime(itemStacks[fuelSlotNumber]) > 0) { burnTimeRemaining[i] = burnTimeInitial[i] = getItemBurnTime(itemStacks[fuelSlotNumber]); --itemStacks[fuelSlotNumber].stackSize; ++burningCount; inventorychanged = true; if (itemStacks[fuelSlotNumber].stackSize == 0) { itemStacks[fuelSlotNumber] = itemStacks[fuelSlotNumber].getItem() .getContainerItem(itemStacks[fuelSlotNumber]); } } } } if (inventorychanged) { markDirty(); } return burningCount; } protected boolean canProcess() { return processItem(false); } protected void processItem() { processItem(true); } protected boolean processItem(boolean performProcess) { Integer firstSuitableInputSlot = null; Integer firstSuitableOutputSlot = null; ItemStack result = null; for (int inputSlot = first_input_slot; inputSlot < first_input_slot + inputSlot; inputSlot++) { if (itemStacks[inputSlot] != null) { result = getProcessingResultForItem(itemStacks[inputSlot]); if (result != null) { for (int outputSlot = first_output_slot; outputSlot < first_output_slot + output_slots; outputSlot++) { ItemStack outputStack = itemStacks[outputSlot]; if (outputStack == null) { firstSuitableInputSlot = inputSlot; firstSuitableOutputSlot = outputSlot; break; } if (outputStack.getItem() == result.getItem() && (!outputStack.getHasSubtypes() || outputStack.getMetadata() == outputStack.getMetadata() && ItemStack.areItemStacksEqual(outputStack, result))) { int combinedSize = itemStacks[outputSlot].stackSize + result.stackSize; if (combinedSize <= getInventoryStackLimit() && combinedSize <= itemStacks[outputSlot].getMaxStackSize()) { firstSuitableInputSlot = inputSlot; firstSuitableOutputSlot = outputSlot; break; } } } if (firstSuitableInputSlot != null) { break; } } } } if (firstSuitableInputSlot == null) { return false; } if (!performProcess) { return true; } itemStacks[firstSuitableInputSlot].stackSize--; if (itemStacks[firstSuitableInputSlot].stackSize <= 0) { itemStacks[firstSuitableInputSlot] = null; } if (itemStacks[firstSuitableOutputSlot] == null) { itemStacks[firstSuitableOutputSlot] = result.copy(); } else { itemStacks[firstSuitableOutputSlot].stackSize += result.stackSize; } markDirty(); return true; } public static short getItemBurnTime(ItemStack stack) { int burnTime = TileEntityFurnace.getItemBurnTime(stack); return (short) MathHelper.clamp_int(burnTime, 0, Short.MAX_VALUE); } public static ItemStack getProcessingResultForItem(ItemStack stack){ return stack; } @Override public void update() { if (canProcess()) { int numberOfFuelBurning = burnFuel(); if (numberOfFuelBurning > 0) { processTime += numberOfFuelBurning; } else { processTime -= 2; } if (processTime < 0) { processTime = 0; } if (processTime >= working_time_for_completion) { processItem(); processTime = 0; } } else { processTime = 0; } int numberBurning = numberOfBurningFuelSlots(); if (cachedNumberOfBurningSlots != numberBurning) { cachedNumberOfBurningSlots = numberBurning; if (worldObj.isRemote) { worldObj.markBlockRangeForRenderUpdate(pos, pos); } worldObj.checkLightFor(EnumSkyBlock.BLOCK, pos); } } @Override public int getSizeInventory() { return itemStacks.length; } @Override public ItemStack getStackInSlot(int index) { return itemStacks[index]; } @Override public ItemStack decrStackSize(int slotIndex, int count) { ItemStack itemStackInSlot = getStackInSlot(slotIndex); if (itemStackInSlot == null){ return null; } ItemStack itemStackRemoved; if (itemStackInSlot.stackSize <= count) { itemStackRemoved = itemStackInSlot; setInventorySlotContents(slotIndex, null); } else { itemStackRemoved = itemStackInSlot.splitStack(count); if (itemStackInSlot.stackSize == 0) { setInventorySlotContents(slotIndex, null); } } markDirty(); return itemStackRemoved; } @Override public void setInventorySlotContents(int slotIndex, ItemStack stack) { itemStacks[slotIndex] = stack; if (stack != null && stack.stackSize > getInventoryStackLimit()) { stack.stackSize = getInventoryStackLimit(); } markDirty(); } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { if (this.worldObj.getTileEntity(this.pos) != this) { return false; } final double x_center_offset = 0.5; final double y_center_offset = 0.5; final double z_center_offset = 0.5; final double maximum_distance_sq = 8.0 * 8.0; return player.getDistanceSq(pos.getX() + x_center_offset, pos.getY() + y_center_offset, pos.getZ() + z_center_offset) < maximum_distance_sq; } public boolean isItemValidForFuelSlot(ItemStack stack) { return false; } public boolean isItemValidForInputSlot(ItemStack stack) { return false; } public boolean isItemValidForOutputSlot(ItemStack stack) { return false; } @Override public NBTTagCompound writeToNBT(NBTTagCompound parentNBTTagCompound) { super.writeToNBT(parentNBTTagCompound); NBTTagList dataForAllSlots = new NBTTagList(); for (int i = 0; i < this.itemStacks.length; i++) { if (this.itemStacks[i] != null) { NBTTagCompound dataForThisSlot = new NBTTagCompound(); dataForThisSlot.setByte("Slot", (byte)i); this.itemStacks[i].writeToNBT(dataForThisSlot); dataForAllSlots.appendTag(dataForThisSlot); } } parentNBTTagCompound.setTag("Items", dataForAllSlots); parentNBTTagCompound.setShort("ProcessTime", processTime); parentNBTTagCompound.setTag("BurnTimeRemaining", new NBTTagIntArray(burnTimeRemaining)); parentNBTTagCompound.setTag("BurnTimeInitial", new NBTTagIntArray(burnTimeInitial)); return parentNBTTagCompound; } @Override public void readFromNBT(NBTTagCompound nbtTagCompound) { super.readFromNBT(nbtTagCompound); final byte nbt_type_compound = 10; NBTTagList dataForAllSlots = nbtTagCompound.getTagList("Items", nbt_type_compound); Arrays.fill(itemStacks, null); for (int i = 0; i < dataForAllSlots.tagCount(); i++) { NBTTagCompound dataForOneSlot = dataForAllSlots.getCompoundTagAt(i); byte slotNumber = dataForOneSlot.getByte("Slot"); if (slotNumber >= 0 && slotNumber < this.itemStacks.length) { this.itemStacks[slotNumber] = ItemStack.loadItemStackFromNBT(dataForOneSlot); } } processTime = nbtTagCompound.getShort("ProcessTime"); burnTimeRemaining = Arrays.copyOf(nbtTagCompound.getIntArray("BurnTimeRemaining"), fuel_slots); burnTimeInitial = Arrays.copyOf(nbtTagCompound.getIntArray("BurnTimeInitial"), fuel_slots); cachedNumberOfBurningSlots = -1; } @SuppressWarnings("rawtypes") public Packet getDescriptionPacket() { NBTTagCompound nbtTagCompound = new NBTTagCompound(); writeToNBT(nbtTagCompound); final int metadata = 0; return new SPacketUpdateTileEntity(this.pos, metadata, nbtTagCompound); } public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { readFromNBT(pkt.getNbtCompound()); } @Override public void clear() { Arrays.fill(itemStacks, null); } @Override public String getName() { return "Set this first"; } @Override public boolean hasCustomName() { return false; } public ITextComponent getDisplayName() { return this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName()); } private static final byte process_field_id = 0; private static final byte first_burn_time_remaining_field_id = 1; private static final byte first_burn_time_initial_field_id = first_burn_time_remaining_field_id + (byte)fuel_slots; private static final byte number_of_fields = first_burn_time_initial_field_id + (byte)fuel_slots; @Override public int getField(int id) { if (id == process_field_id) { return 0; } if (id >= first_burn_time_remaining_field_id && id < first_burn_time_remaining_field_id + (byte)fuel_slots) { return burnTimeRemaining[id - first_burn_time_remaining_field_id]; } if (id >= first_burn_time_initial_field_id && id < first_burn_time_initial_field_id + (byte)fuel_slots) { return burnTimeInitial[id - first_burn_time_initial_field_id]; } System.err.println("Invalid field ID in TileInventoryProcessing.getField: " + id); return 0; } @Override public void setField(int id, int value) { if (id == process_field_id) { processTime = (short)value; } else if (id >= first_burn_time_remaining_field_id && id < first_burn_time_remaining_field_id + fuel_slots) { burnTimeRemaining[id - first_burn_time_remaining_field_id] = value; } else if (id >= first_burn_time_initial_field_id && id < first_burn_time_initial_field_id + fuel_slots) { burnTimeInitial[id - first_burn_time_initial_field_id] = value; } else { System.err.println("Invalid field ID in TileInventoryProcessing.getField: " + id); } } @Override public int getFieldCount() { return number_of_fields; } @Override public boolean isItemValidForSlot(int index, ItemStack stack) { return false; } @Override public ItemStack removeStackFromSlot(int slotIndex) { ItemStack stack = getStackInSlot(slotIndex); if (stack != null) { setInventorySlotContents(slotIndex, null); } return stack; } @Override public void openInventory(EntityPlayer player) { // TODO Auto-generated method stub } @Override public void closeInventory(EntityPlayer player) { // TODO Auto-generated method stub } }
-
I have made a custom block (flux grinder) which is loaded into the world perfectly fine. I tried making a custom gui (so that it has a working second output slot), but not only am I having troubles aligning it properly, it also crashes once I hover over the place where the inputslot is being put right now (which is not aligned properly) GuiFluxGrinder: package com.messy.core.gui; import java.awt.Color; import java.util.ArrayList; import java.util.List; import com.messy.core.Reference; import com.messy.core.containers.ContainerFluxGrinder; import com.messy.core.tileentities.TileEntityFluxGrinder; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class GuiFluxGrinder extends GuiContainer { private static final ResourceLocation texture = new ResourceLocation(Reference.MOD_ID + ":textures/gui/flux_grinder_gui.png"); private final TileEntityFluxGrinder entity; public GuiFluxGrinder(InventoryPlayer player, TileEntityFluxGrinder entity) { super(new ContainerFluxGrinder(player, entity)); xSize = 176; ySize = 166; this.entity = entity; } final int process_bar_xpos = 49; final int process_bar_ypos = 60; final int process_bar_icon_u = 176; final int process_bar_icon_v = 14; final int process_bar_width = 24; final int process_bar_height = 17; final int flame_xpos = 57; final int flame_ypos = 37; final int flame_icon_u = 176; final int flame_icon_v = 0; final int flame_width = 14; final int flame_height = 14; final int flame_x_spacing = 18; /** * Args : renderPartialTicks, mouseX, mouseY */ @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { Minecraft.getMinecraft().getTextureManager().bindTexture(texture); GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, xSize, ySize); double processProgress = entity.fractionOfProcessingTimeComplete(); this.drawTexturedModalRect(this.guiLeft + process_bar_xpos, this.guiTop + process_bar_ypos, process_bar_icon_u, process_bar_icon_v, (int)(processProgress * process_bar_width), process_bar_height); for ( int i = 0; i < entity.fuel_slots; i++) { double burnRemaining = entity.fractionOfFuelRemaining(i); int yOffset = (int)((1.0 - burnRemaining) * flame_height); this.drawTexturedModalRect(guiLeft + flame_xpos + flame_x_spacing * i, guiTop + flame_ypos + yOffset, flame_icon_u, flame_icon_v + yOffset, flame_width, flame_height - yOffset); } } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { super.drawGuiContainerForegroundLayer(mouseX, mouseY); final int label_xpos = 5; final int label_ypos = 5; fontRendererObj.drawString(entity.getDisplayName().getUnformattedText(), label_xpos, label_ypos, Color.DARK_GRAY.getRGB()); List<String> text = new ArrayList<String>(); if (isInRect(guiLeft + process_bar_xpos, guiTop + process_bar_ypos, process_bar_width, process_bar_height, mouseX, mouseY)) { text.add("Progress:"); int processPercentage = (int)(entity.fractionOfProcessingTimeComplete() * 100); text.add(processPercentage + "%"); } for(int i = 0; i < entity.fuel_slots; i++) { if (isInRect(guiLeft + flame_xpos + flame_x_spacing * i, guiTop + flame_ypos, flame_width, flame_height, mouseX, mouseY)) { text.add("Fuel Time: "); text.add(entity.secondsOfFuelRemaining(i) + "s"); } } if (!text.isEmpty()) { drawHoveringText(text, mouseX - guiLeft, mouseY - guiTop, fontRendererObj); } } public static boolean isInRect(int x, int y, int xSize, int ySize, int mouseX, int mouseY) { return ((mouseX >= x && mouseX <= x + xSize) && (mouseY >= y && mouseY <= y + ySize)); } } GuiHandlerFluxGrinder: package com.messy.core.gui; import com.messy.core.containers.ContainerFluxGrinder; import com.messy.core.tileentities.TileEntityFluxGrinder; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; public class GuiHandlerFluxGrinder implements IGuiHandler { public static final int FLUX_GRINDER_GUI = 34; public static int getGUIID() { return FLUX_GRINDER_GUI; } @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if (ID == FLUX_GRINDER_GUI) { return new ContainerFluxGrinder(player.inventory, (TileEntityFluxGrinder)world.getTileEntity(new BlockPos(x, y, z))); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if (ID == FLUX_GRINDER_GUI) { return new GuiFluxGrinder(player.inventory, (TileEntityFluxGrinder)world.getTileEntity(new BlockPos(x, y, z))); } return null; } } Crashlog: What am I missing here?
-
Fixed it. The problem was that the property-name and the int name were the same so it couldn't differantiate (is that how you spell that? )
-
In Eclipse I'm getting an error on the getValue. The error is: The method getValue(IProperty<T>) in the type IBlockState is not applicable for the arguments (int) In the same file I define the field like this: protected static PropertyInteger burningSides; @Override public int getLightValue(IBlockAccess world, BlockPos pos) { int lightValue = 0; IBlockState state = getActualState(getDefaultState(), world, pos); int burningSides = (Integer)state.getValue(burningSides); switch (burningSides) { case 4: lightValue += (int)((four_side_light_value - three_side_light_value) / (4.0 - 3.0) * burningSides); case 3: lightValue += (int)((three_side_light_value - two_side_light_value) / (3.0 - 2.0) * burningSides); case 2: lightValue += (int)((two_side_light_value - one_side_light_value) / (2.0 - 1.0) * burningSides); case 1: lightValue += one_side_light_value; break; default: break; } lightValue = MathHelper.clamp_int(lightValue, 0, four_side_light_value); return lightValue; } How do I deal with this? I'm following a where this same code does not generate an error.
-
In your entity registration, I noticed the one bugging out is also the only one using EnumCreatureType.MONSTER. Might be related, but I have no knowledge of mobspawning so far.
-
That sounds like a loop to me, but it did fix the error so.... we'll see
-
I understood that part, but I have no clue what compound I should return...
-
I have a small problem with the following code @Override public void writeToNBT(NBTTagCompound parentNBTTagCompound) { super.writeToNBT(parentNBTTagCompound); NBTTagList dataForAllSlots = new NBTTagList(); for (int i = 0; i < this.itemStacks.length; i++) { if (this.itemStacks[i] != null) { NBTTagCompound dataForThisSlot = new NBTTagCompound(); dataForThisSlot.setByte("Slot", (byte)i); this.itemStacks[i].writeToNBT(dataForThisSlot); dataForAllSlots.appendTag(dataForThisSlot); } } parentNBTTagCompound.setTag("Items", dataForAllSlots); parentNBTTagCompound.setShort("ProcessTime", processTime); parentNBTTagCompound.setTag("BurnTimeRemaining", new NBTTagIntArray(burnTimeRemaining)); parentNBTTagCompound.setTag("BurnTimeInitial", new NBTTagIntArray(burnTimeInitial)); } Apparently TileEntity.writeToNBT has a returntype of the type NBTTagCompound. Any suggestions on how to solve this problem?
-
I made it work by adjusting the model that I made in MrCrayFish's model creator Edit: aaaand that somehow broke the way the model loaded into the inventory... what on earth Edit 2: fixed problem from the edit by adding "parent": "block/orientable", mcf model creator doesn't add that by default...
-
Your suggestion doesn't work, because I can't call a static method of a parent like that (apparently) super can't be used in a static method Believe me, I tried My json for the grinder is now this, but that doesn't make a difference: { "variants": { "facing=north": { "model": "messycore:flux_grinder", "y": 180 }, "facing=south": { "model": "messycore:flux_grinder" }, "facing=west": { "model": "messycore:flux_grinder", "y": 270 }, "facing=east": { "model": "messycore:flux_grinder", "y": 90 }, "inventory": { "model": "messycore:flux_grinder" } } }
-
Yeah, but it is easy to fix and not even that big of a problem
-
I got it working through a parent class (look below) tha I can use for all machines I might make. I messed up the model orientations though because they face away from the player package com.messy.core.blocks; import java.util.Random; import javax.annotation.Nullable; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Blocks; import net.minecraft.inventory.Container; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public abstract class BlockMachine extends ModBlock { public static final PropertyDirection FACING = BlockHorizontal.FACING; private final boolean isWorking; protected static boolean keepInventory; public BlockMachine(String unlocalizedName, String registryName, Material material, boolean isWorking) { super(unlocalizedName, registryName, material); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); this.isWorking = isWorking; } @Nullable public Item getItemDropped(IBlockState state, Random rand, int fortune) { return Item.getItemFromBlock(Blocks.FURNACE); } public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { this.setDefaultFacing(worldIn, pos, state); } private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state) { if (!worldIn.isRemote) { IBlockState iblockstate = worldIn.getBlockState(pos.north()); IBlockState iblockstate1 = worldIn.getBlockState(pos.south()); IBlockState iblockstate2 = worldIn.getBlockState(pos.west()); IBlockState iblockstate3 = worldIn.getBlockState(pos.east()); EnumFacing enumfacing = (EnumFacing)state.getValue(FACING); if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock()) { enumfacing = EnumFacing.SOUTH; } else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock()) { enumfacing = EnumFacing.NORTH; } else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock()) { enumfacing = EnumFacing.EAST; } else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock()) { enumfacing = EnumFacing.WEST; } worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2); } } public static void setState(boolean active, World worldIn, BlockPos pos, BlockMachine workingBlock, BlockMachine notWorkingBlock) { IBlockState iblockstate = worldIn.getBlockState(pos); TileEntity tileentity = worldIn.getTileEntity(pos); keepInventory = true; if (active) { worldIn.setBlockState(pos, workingBlock.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3); worldIn.setBlockState(pos, workingBlock.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3); } else { worldIn.setBlockState(pos, notWorkingBlock.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3); worldIn.setBlockState(pos, notWorkingBlock.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3); } keepInventory = false; if (tileentity != null) { tileentity.validate(); worldIn.setTileEntity(pos, tileentity); } } public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()); } public boolean hasComparatorInputOverride(IBlockState state) { return true; } public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos) { return Container.calcRedstone(worldIn.getTileEntity(pos)); } public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state, BlockMachine item) { return new ItemStack(item); } /** * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render */ public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.MODEL; } /** * Convert the given metadata into a BlockState for this Block */ public IBlockState getStateFromMeta(int meta) { EnumFacing enumfacing = EnumFacing.getFront(meta); if (enumfacing.getAxis() == EnumFacing.Axis.Y) { enumfacing = EnumFacing.NORTH; } return this.getDefaultState().withProperty(FACING, enumfacing); } /** * Convert the BlockState into the correct metadata value */ public int getMetaFromState(IBlockState state) { return ((EnumFacing)state.getValue(FACING)).getIndex(); } /** * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed * blockstate. */ public IBlockState withRotation(IBlockState state, Rotation rot) { return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING))); } /** * Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed * blockstate. */ public IBlockState withMirror(IBlockState state, Mirror mirrorIn) { return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING))); } protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {FACING}); } } package com.messy.core.blocks; import com.messy.core.ModBlocks; import com.messy.core.tileentities.TileEntityFluxGrinder; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.inventory.InventoryHelper; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class BlockFluxGrinder extends BlockMachine { public BlockFluxGrinder() { super("flux_grinder", "flux_grinder", Material.ROCK, false); } public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityFluxGrinder(); } public static void setState(boolean active, World worldIn, BlockPos pos) { BlockMachine.setState(active, worldIn, pos, ModBlocks.FLUXGRINDERWORKING, ModBlocks.FLUXGRINDER); } public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2); if (stack.hasDisplayName()) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityFluxGrinder) { ((TileEntityFluxGrinder)tileentity).setCustomInventoryName(stack.getDisplayName()); } } } public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { if (!keepInventory) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityFluxGrinder) { InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityFluxGrinder)tileentity); worldIn.updateComparatorOutputLevel(pos, this); } } super.breakBlock(worldIn, pos, state); } public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) { return super.getItem(worldIn, pos, state, ModBlocks.FLUXGRINDER); } }
-
I guess I just didn't look hard enough... Tryijng right now to make it work