Jump to content

Pyrocake

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by Pyrocake

  1. 6 hours ago, Maxi07 said:

    I think Iyour main class NewDawn has to annotated with @EventBusSubscriber(modid = [your_modid], bus = Bus.MOD), but leave "@Mod"

    Then the methods with @SubribeEvent (like your ore gen) will be executed

     

    I used 

    @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)

    And that made it work, thank you!

  2. I have been following TurtyWurty's tutorial on how to add Ore Generation to a mod, and I have followed it fully as much as I am aware. I have created a new world, and I cannot find it anywhere. It does load properly as an item, so that isn't the problem. Here is my code

     

    RegistryHandler.java

    package com.booktail.newdawn.util;
    
    import com.booktail.newdawn.NewDawn;
    import com.booktail.newdawn.blocks.BlockItemBase;
    import com.booktail.newdawn.blocks.PrismallonBlock;
    import com.booktail.newdawn.blocks.PrismallonOreBlock;
    import com.booktail.newdawn.items.ItemBase;
    import net.minecraft.block.Block;
    import net.minecraft.item.Item;
    import net.minecraftforge.fml.RegistryObject;
    import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
    import net.minecraftforge.registries.DeferredRegister;
    import net.minecraftforge.registries.ForgeRegistries;
    
    public class RegistryHandler {
    
        public static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, NewDawn.MOD_ID);
        public static final DeferredRegister<Block> BLOCKS = new DeferredRegister<Block>(ForgeRegistries.BLOCKS, NewDawn.MOD_ID);
    
        public static void init() {
            ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
            BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
        }
    
        //Item Declaration for "Hello World"
        public static final RegistryObject<Item> DINGUS = ITEMS.register("dingus", ItemBase::new);
    
        //Items
        public static final RegistryObject<Item> PRISMALLON_INGOT = ITEMS.register("prismallon_ingot", ItemBase::new);
    
        //Blocks (and Block Items)
        public static final RegistryObject<Block> PRISMALLON_BLOCK = BLOCKS.register("prismallon_block", PrismallonBlock::new);
        public static final RegistryObject<Item> PRISMALLON_BLOCK_ITEM = ITEMS.register("prismallon_block", ()-> new BlockItemBase(PRISMALLON_BLOCK.get()));
    
        public static final RegistryObject<Block> PRISMALLON_ORE_BLOCK = BLOCKS.register("prismallon_ore_block", PrismallonOreBlock::new);
        public static final RegistryObject<Item> PRISMALLON_ORE_BLOCK_ITEM = ITEMS.register("prismallon_ore_block", ()-> new BlockItemBase(PRISMALLON_ORE_BLOCK.get()));
    
    }

     

    NewDawnOreGen.java

    package com.booktail.newdawn.world.gen;
    
    import com.booktail.newdawn.util.RegistryHandler;
    import net.minecraft.world.biome.Biome;
    import net.minecraft.world.gen.GenerationStage;
    import net.minecraft.world.gen.feature.Feature;
    import net.minecraft.world.gen.feature.OreFeatureConfig;
    import net.minecraft.world.gen.placement.ConfiguredPlacement;
    import net.minecraft.world.gen.placement.CountRangeConfig;
    import net.minecraft.world.gen.placement.Placement;
    import net.minecraftforge.registries.ForgeRegistries;
    
    public class NewDawnOreGen {
    
        public static void generateOre() {
            for(Biome biome : ForgeRegistries.BIOMES){
                ConfiguredPlacement customConfig = Placement.COUNT_RANGE.configure(new CountRangeConfig(20,5,5,25));
                biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Feature.ORE
                        .withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, RegistryHandler.PRISMALLON_ORE_BLOCK.get().getDefaultState(), 10))
                        .withPlacement(customConfig));
            }
        }
    
    }

     

    and NewDawn.java

    package com.booktail.newdawn;
    
    import com.booktail.newdawn.util.RegistryHandler;
    import com.booktail.newdawn.world.gen.NewDawnOreGen;
    import net.minecraft.block.Block;
    import net.minecraft.block.Blocks;
    import net.minecraft.item.ItemGroup;
    import net.minecraft.item.ItemStack;
    import net.minecraftforge.common.MinecraftForge;
    import net.minecraftforge.event.RegistryEvent;
    import net.minecraftforge.eventbus.api.SubscribeEvent;
    import net.minecraftforge.fml.InterModComms;
    import net.minecraftforge.fml.common.Mod;
    import net.minecraftforge.fml.event.lifecycle.*;
    import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
    import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
    import org.apache.logging.log4j.LogManager;
    import org.apache.logging.log4j.Logger;
    
    import java.util.stream.Collectors;
    
    @Mod("newdawn")
    public class NewDawn {
        private static final Logger LOGGER = LogManager.getLogger();
        public static final String MOD_ID = "newdawn";
    
        public NewDawn() {
            FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
            FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
            FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
            FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
            //FML Listeners setup completed
    
            RegistryHandler.init();
    
            MinecraftForge.EVENT_BUS.register(this);
        }
    
        @SubscribeEvent
        public static void loadCompleteEvent(FMLLoadCompleteEvent event){
            NewDawnOreGen.generateOre();
        }
    
        private void setup(final FMLCommonSetupEvent event) {
            // some preinit confirmation code
            LOGGER.info("Preinit is successful. Check Dirt registry below.");
            LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
        }
    
        private void doClientStuff(final FMLClientSetupEvent event) {
            // client test
            LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
        }
    
        private void enqueueIMC(final InterModEnqueueEvent event) {
            // hello world
            InterModComms.sendTo("newdawn", "helloworld", () -> {
                LOGGER.info("Hello world from the MDK");
                return "Hello world";
            });
        }
    
        private void processIMC(final InterModProcessEvent event) {
            // some example code to receive and process InterModComms from other mods
            LOGGER.info("Got IMC {}", event.getIMCStream().
                    map(m -> m.getMessageSupplier().get()).
                    collect(Collectors.toList()));
        }
    
        // You can use SubscribeEvent and let the Event Bus discover methods to call
        @SubscribeEvent
        public void onServerStarting(FMLServerStartingEvent event) {
            // do something when the server starts
            LOGGER.info("HELLO from server starting");
        }
    
        // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
        // Event bus for receiving Registry Events)
        @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
        public static class RegistryEvents {
            @SubscribeEvent
            public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
                // register a new block here
                LOGGER.info("HELLO from Register Block");
            }
        }
    
        public static final ItemGroup TAB = new ItemGroup("newdawnTab") {
    
            @Override
            public ItemStack createIcon() {
                return new ItemStack(RegistryHandler.PRISMALLON_INGOT.get());
            }
        };
    }

     

    I would greatly appreciate any help. I don't know why ore generation isn't happening in new worlds

  3. I have a basic 2 reagent furnace I've built (more Frankensteined, but that's beside the point) and it works exactly as intended, except for when the world is re-opened. It has two visual states, one for when isBurning is false, and one for when isBurning is true. This function works correctly in normal conditions. When the world is loaded, a furnace must be emptied of its burn time and refilled before it will correctly reload the visual appearance. Here is my code: 

    TileEntityNewDawnPrismallon.Java

    package com.booktail.anewdawn.blocks.machines;
    
    import javax.annotation.Nullable;
    
    import net.minecraft.block.Block;
    import net.minecraft.block.material.Material;
    import net.minecraft.block.properties.PropertyBool;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.init.Blocks;
    import net.minecraft.init.Items;
    import net.minecraft.inventory.IInventory;
    import net.minecraft.inventory.ItemStackHelper;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemBlock;
    import net.minecraft.item.ItemHoe;
    import net.minecraft.item.ItemStack;
    import net.minecraft.item.ItemSword;
    import net.minecraft.item.ItemTool;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.network.play.server.SPacketUpdateTileEntity;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.ITickable;
    import net.minecraft.util.NonNullList;
    import net.minecraft.util.math.BlockPos;
    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.World;
    import net.minecraftforge.fml.common.registry.GameRegistry;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    
    public class TileEntityNewDawnPrismallon extends TileEntity implements IInventory, ITickable
    {
    	private NonNullList<ItemStack> inventory = NonNullList.<ItemStack>withSize(4, ItemStack.EMPTY);
    	private String customName;
    	
    	private int burnTime;
    	private int currentBurnTime;
    	private int cookTime;
    	private int totalCookTime;
    	
    	@Override
    	public String getName() 
    	{
    		return this.hasCustomName() ? this.customName : "container.PrismallonFurnace";
    	}
    
    	@Override
    	public boolean hasCustomName() 
    	{
    		return this.customName != null && !this.customName.isEmpty();
    	}
    	
    	public void setCustomName(String customName) 
    	{
    		this.customName = customName;
    	}
    	
    	@Override
    	public ITextComponent getDisplayName() 
    	{
    		return this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName());
    	}
    
    	@Override
    	public int getSizeInventory() 
    	{
    		return this.inventory.size();
    	}
    
    	@Override
    	public boolean isEmpty() 
    	{
    		for(ItemStack stack : this.inventory)
    		{
    			if(!stack.isEmpty()) return false;
    		}
    		return true;
    	}
    
    	@Override
    	public ItemStack getStackInSlot(int index)
    	{
    		return (ItemStack)this.inventory.get(index);
    	}
    
    	@Override
    	public ItemStack decrStackSize(int index, int count) 
    	{
    		return ItemStackHelper.getAndSplit(this.inventory, index, count);
    	}
    
    	@Override
    	public ItemStack removeStackFromSlot(int index) 
    	{
    		return ItemStackHelper.getAndRemove(this.inventory, index);
    	}
    
    	@Override
    	public void setInventorySlotContents(int index, ItemStack stack) 
    	{
    		ItemStack itemstack = (ItemStack)this.inventory.get(index);
    		boolean flag = !stack.isEmpty() && stack.isItemEqual(itemstack) && ItemStack.areItemStackTagsEqual(stack, itemstack);
    		this.inventory.set(index, stack);
    		
    		if(stack.getCount() > this.getInventoryStackLimit()) stack.setCount(this.getInventoryStackLimit());
    		if(index == 0 && index + 1 == 1 && !flag)
    		{
    			ItemStack stack1 = (ItemStack)this.inventory.get(index + 1);
    			this.totalCookTime = this.getCookTime(stack, stack1);
    			this.cookTime = 0;
    			this.markDirty();
    		}
    	}
    	
    	@Override
    	public void readFromNBT(NBTTagCompound compound)
    	{
    		super.readFromNBT(compound);
    		this.inventory = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
    		ItemStackHelper.loadAllItems(compound, this.inventory);
    		this.burnTime = compound.getInteger("BurnTime");
    		this.cookTime = compound.getInteger("CookTime");
    		this.totalCookTime = compound.getInteger("CookTimeTotal");
    		this.currentBurnTime = getItemBurnTime((ItemStack)this.inventory.get(2));
    		
    		if(compound.hasKey("CustomName", 8)) this.setCustomName(compound.getString("CustomName"));
    	}
    	
    	@Override
    	public NBTTagCompound writeToNBT(NBTTagCompound compound) 
    	{
    		super.writeToNBT(compound);
    		compound.setInteger("BurnTime", (short)this.burnTime);
    		compound.setInteger("CookTime", (short)this.cookTime);
    		compound.setInteger("CookTimeTotal", (short)this.totalCookTime);
    		ItemStackHelper.saveAllItems(compound, this.inventory);
    		
    		if(this.hasCustomName()) compound.setString("CustomName", this.customName);
    		return compound;
    	}
    
    	@Override
    	public int getInventoryStackLimit() 
    	{
    		return 64;
    	}
    	
    	public boolean isBurning() 
    	{
    		return this.burnTime > 0;
    	}
    	
    	@SideOnly(Side.CLIENT)
    	public static boolean isBurning(IInventory inventory) 
    	{
    		return inventory.getField(0) > 0;
    	}
    	
    	public void update() 
    	{
    		boolean flag = this.isBurning();
    		boolean flag1 = false;
    		
    		if(this.isBurning()) --this.burnTime;
    		
    		if(!this.world.isRemote) 
    		{
    		
    			ItemStack stack = (ItemStack)this.inventory.get(2);
    			
    			if(this.isBurning() || !stack.isEmpty() && !((((ItemStack)this.inventory.get(0)).isEmpty()) || ((ItemStack)this.inventory.get(1)).isEmpty())) 
    			{
    				if(!this.isBurning() && this.canSmelt()) 
    				{
    					this.burnTime = getItemBurnTime(stack);
    					this.currentBurnTime = this.burnTime;
    					
    					if(this.isBurning()) 
    					{
    						
    						flag1 = true;
    					
    						
    						if(!stack.isEmpty()) 
    						{
    							Item item = stack.getItem();
    							stack.shrink(1);
    							
    							if(stack.isEmpty()) 
    							{
    								ItemStack item1 = item.getContainerItem(stack);
    								this.inventory.set(2, item1);
    							}
    						}
    					}
    				} 
    				if(this.isBurning() && this.canSmelt()) 
    				{
    					++this.cookTime;
    					
    					if(this.cookTime == this.totalCookTime) 
    					{
    						this.cookTime = 0;
    						this.totalCookTime = this.getCookTime((ItemStack)this.inventory.get(0), (ItemStack)this.inventory.get(1));
    						this.smeltItem();
    						flag1 = true;
    					}
    				} 
    				else this.cookTime = 0;
    			} 
    			else if(!this.isBurning() && this.cookTime > 0) 
    			{
    				this.cookTime = MathHelper.clamp(this.cookTime - 2, 0, this.totalCookTime);
    			}
    			
    			
    			if(this.isBurning()) 
    			{
    				flag1 = true;
    				PrismallonFurnaceBlock.setState(this.isBurning(), this.world, this.pos);
    			}
    		} 
    		if(flag1) this.markDirty();
    	}
    	
    	public int getCookTime(ItemStack input1, ItemStack input2) 
    	{
    		return 200;
    	}
    	
    	private boolean canSmelt() 
    	{
    		if(((ItemStack)this.inventory.get(0)).isEmpty() || ((ItemStack)this.inventory.get(1)).isEmpty()) return false;
    		else 
    		{
    			ItemStack result = PrismallonFurnaceRecipes.getInstance().getPrismallonResult((ItemStack)this.inventory.get(0), (ItemStack)this.inventory.get(1));	
    			if(result.isEmpty()) return false;
    			else
    			{
    				ItemStack output = (ItemStack)this.inventory.get(3);
    				if(output.isEmpty()) return true;
    				if(!output.isItemEqual(result)) return false;
    				int res = output.getCount() + result.getCount();
    				return res <= getInventoryStackLimit() && res <= output.getMaxStackSize();
    			}
    		}
    	}
    	
    	public void smeltItem() 
    	{
    		if(this.canSmelt()) 
    		{
    			ItemStack input1 = (ItemStack)this.inventory.get(0);
    			ItemStack input2 = (ItemStack)this.inventory.get(1);
    			ItemStack result = PrismallonFurnaceRecipes.getInstance().getPrismallonResult(input1, input2);
    			ItemStack output = (ItemStack)this.inventory.get(3);
    			
    			if(output.isEmpty()) this.inventory.set(3, result.copy());
    			else if(output.getItem() == result.getItem()) output.grow(result.getCount());
    			
    			input1.shrink(1);
    			input2.shrink(1);
    		}
    	}
    	
    	public static int getItemBurnTime(ItemStack fuel) 
    	{
    		if(fuel.isEmpty()) return 0;
    		else 
    		{
    			Item item = fuel.getItem();
    
    			if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.AIR) 
    			{
    				Block block = Block.getBlockFromItem(item);
    
    				if (block == Blocks.WOODEN_SLAB) return 150;
    				if (block.getDefaultState().getMaterial() == Material.WOOD) return 300;
    				if (block == Blocks.COAL_BLOCK) return 16000;
    			}
    
    			if (item instanceof ItemTool && "WOOD".equals(((ItemTool)item).getToolMaterialName())) return 200;
    			if (item instanceof ItemSword && "WOOD".equals(((ItemSword)item).getToolMaterialName())) return 200;
    			if (item instanceof ItemHoe && "WOOD".equals(((ItemHoe)item).getMaterialName())) return 200;
    			if (item == Items.STICK) return 100;
    			if (item == Items.COAL) return 1600;
    			if (item == Items.LAVA_BUCKET) return 20000;
    			if (item == Item.getItemFromBlock(Blocks.SAPLING)) return 100;
    			if (item == Items.BLAZE_ROD) return 2400;
    
    			return GameRegistry.getFuelValue(fuel);
    		}
    	}
    		
    	public static boolean isItemFuel(ItemStack fuel)
    	{
    		return getItemBurnTime(fuel) > 0;
    	}
    	
    	@Override
    	public boolean isUsableByPlayer(EntityPlayer player) 
    	{
    		return this.world.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
    	}
    
    	@Override
    	public void openInventory(EntityPlayer player) {}
    
    	@Override
    	public void closeInventory(EntityPlayer player) {}
    
    	@Override
    	public boolean isItemValidForSlot(int index, ItemStack stack) 
    	{
    		
    		if(index == 3) return false;
    		else if(index != 2) return true;
    		else 
    		{
    			return isItemFuel(stack);
    		}
    	}
    	
    	public String getGuiID() 
    	{
    		return "newdawn.prismallonfurnace";
    	}
    
    	@Override
    	public int getField(int id) 
    	{
    		switch(id) 
    		{
    		case 0:
    			return this.burnTime;
    		case 1:
    			return this.currentBurnTime;
    		case 2:
    			return this.cookTime;
    		case 3:
    			return this.totalCookTime;
    		default:
    			return 0;
    		}
    	}
    
    	@Override
    	public void setField(int id, int value) 
    	{
    		switch(id) 
    		{
    		case 0:
    			this.burnTime = value;
    			break;
    		case 1:
    			this.currentBurnTime = value;
    			break;
    		case 2:
    			this.cookTime = value;
    			break;
    		case 3:
    			this.totalCookTime = value;
    		}
    	}
    
    	@Override
    	public int getFieldCount() 
    	{
    		return 4;
    	}
    
    	@Override
    	public void clear() 
    	{
    		this.inventory.clear();
    	}
    	
    }

    PrismallonFurnaceBlock.Java

    package com.booktail.anewdawn.blocks.machines;
    
    import java.util.Random;
    
    import javax.annotation.Nullable;
    
    import com.booktail.anewdawn.Main;
    import com.booktail.anewdawn.blocks.BlockBase;
    import com.booktail.anewdawn.init.ModBlocks;
    import com.booktail.anewdawn.util.Reference;
    
    import net.minecraft.block.Block;
    import net.minecraft.block.BlockContainer;
    import net.minecraft.block.BlockHorizontal;
    import net.minecraft.block.ITileEntityProvider;
    import net.minecraft.block.SoundType;
    import net.minecraft.block.material.Material;
    import net.minecraft.block.properties.IProperty;
    import net.minecraft.block.properties.PropertyBool;
    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.entity.player.EntityPlayer;
    import net.minecraft.init.Blocks;
    import net.minecraft.init.Items;
    import net.minecraft.inventory.InventoryHelper;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.EnumActionResult;
    import net.minecraft.util.EnumBlockRenderType;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.util.EnumHand;
    import net.minecraft.util.Mirror;
    import net.minecraft.util.Rotation;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.text.TextComponentString;
    import net.minecraft.world.World;
    
    public class PrismallonFurnaceBlock extends BlockBase implements ITileEntityProvider
    {
    	
    	public static final PropertyDirection FACING = BlockHorizontal.FACING;
    	public static final PropertyBool BURNING = PropertyBool.create("burning");
    
    	public PrismallonFurnaceBlock(String name, Material material)
    	    {
    	        super(name, material);
    	        setHardness(5.0f);
    			setResistance(30.0f);
    			setHarvestLevel("pickaxe", 1);
    			this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(BURNING, false));
    	    }
    
    	@Override
    	public Item getItemDropped(IBlockState state, Random rand, int fortune) {
    		return Item.getItemFromBlock(ModBlocks.PRISMALLON_FURNACE_BLOCK);
    	}
    	
    	@Override
    	public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
    		return new ItemStack(ModBlocks.PRISMALLON_FURNACE_BLOCK);
    	}
    	
    	@Override
    	public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    		if(!worldIn.isRemote) 
    		{
    			playerIn.openGui(Main.instance, Reference.GUI_PRISMALLON_FURNACE_BLOCK, worldIn, pos.getX(), pos.getY(), pos.getZ());
    		}
    		
    			return true;
    		
    	}
    	
    	@Override
    	public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
    		{
    			if (!worldIn.isRemote) 
    	        {
    	            IBlockState north = worldIn.getBlockState(pos.north());
    	            IBlockState south = worldIn.getBlockState(pos.south());
    	            IBlockState west = worldIn.getBlockState(pos.west());
    	            IBlockState east = worldIn.getBlockState(pos.east());
    	            EnumFacing face = (EnumFacing)state.getValue(FACING);
    
    	            if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) face = EnumFacing.SOUTH;
    	            else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) face = EnumFacing.NORTH;
    	            else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) face = EnumFacing.EAST;
    	            else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) face = EnumFacing.WEST;
    	            worldIn.setBlockState(pos, state.withProperty(FACING, face), 2);
    	        }
    		}
    	}
    	
    	public static void setState(boolean active, World worldIn, BlockPos pos) 
    	{
    		IBlockState state = worldIn.getBlockState(pos);
    		TileEntity tileentity = worldIn.getTileEntity(pos);
    
    		if(active) worldIn.setBlockState(pos, ModBlocks.PRISMALLON_FURNACE_BLOCK.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(BURNING, true), 3);
    		else worldIn.setBlockState(pos, ModBlocks.PRISMALLON_FURNACE_BLOCK.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(BURNING, false), 3);
    		
    		if(tileentity != null) 
    		{
    			tileentity.validate();
    			worldIn.setTileEntity(pos, tileentity);
    		}
    
    	
    		
    		
    		
    		
    		
    		
    	}
    	
    	@Override
    	public TileEntity createNewTileEntity(World worldIn, int meta) {
    		
    		return new TileEntityNewDawnPrismallon();
    				
    	}
    	
    	@Override
    	public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) 
    	{
    		return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
    	}
    	
    	@Override
    	public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) 
    	{
    		worldIn.setBlockState(pos, this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
    		
    		
    		
    		
    		
    		
    		
    	}
    	
    	@Override
    	public void breakBlock(World worldIn, BlockPos pos, IBlockState state) 
    	{
    		TileEntityNewDawnPrismallon tileentity = (TileEntityNewDawnPrismallon)worldIn.getTileEntity(pos);
    		InventoryHelper.dropInventoryItems(worldIn, pos, tileentity);
    		super.breakBlock(worldIn, pos, state);
    	}
    	
    	
    	@Override
    	public EnumBlockRenderType getRenderType(IBlockState state) 
    	{
    		return EnumBlockRenderType.MODEL;
    	}
    	
    	@Override
    	public IBlockState withRotation(IBlockState state, Rotation rot)
    	{
    		return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
    	}
    	
    	@Override
    	public IBlockState withMirror(IBlockState state, Mirror mirrorIn) 
    	{
    		return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
    	}
    	
    	@Override
    	protected BlockStateContainer createBlockState() 
    	{
    		return new BlockStateContainer(this, new IProperty[] {BURNING,FACING});
    	}
    	
    	@Override
    	public IBlockState getStateFromMeta(int meta) 
    	{
    		EnumFacing facing = EnumFacing.getFront(meta);
    		if(facing.getAxis() == EnumFacing.Axis.Y) facing = EnumFacing.NORTH;
    		return this.getDefaultState().withProperty(FACING, facing);
    	}
    	
    	@Override
    	public int getMetaFromState(IBlockState state) 
    	{
    		return ((EnumFacing)state.getValue(FACING)).getIndex();
    		
    	}	
    	
    	
    }

    ContainerPrismallon.Java

    package com.booktail.anewdawn.blocks.machines;
    
    import com.booktail.anewdawn.blocks.machines.slots.SlotPrismallonFuel;
    import com.booktail.anewdawn.blocks.machines.slots.SlotPrismallonOutput;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.inventory.Container;
    import net.minecraft.inventory.IContainerListener;
    import net.minecraft.inventory.Slot;
    import net.minecraft.item.ItemStack;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    
    public class ContainerPrismallon extends Container
    {
    	private final TileEntityNewDawnPrismallon tileentity;
    	private int cookTime, totalCookTime, burnTime, currentBurnTime;
    	
    	public ContainerPrismallon(InventoryPlayer player, TileEntityNewDawnPrismallon tileentity) 
    	{
    		this.tileentity = tileentity;
    		
    		this.addSlotToContainer(new Slot(tileentity, 0, 43, 17));
    		this.addSlotToContainer(new Slot(tileentity, 1, 69, 17));
    		this.addSlotToContainer(new SlotPrismallonFuel(tileentity, 2, 56, 53));
    		this.addSlotToContainer(new SlotPrismallonOutput(player.player, tileentity, 3, 116, 35));
    		
    		for(int y = 0; y < 3; y++)
    		{
    			for(int x = 0; x < 9; x++)
    			{
    				this.addSlotToContainer(new Slot(player, x + y*9 + 9, 8 + x*18, 84 + y*18));
    			}
    		}
    		
    		for(int x = 0; x < 9; x++)
    		{
    			this.addSlotToContainer(new Slot(player, x, 8 + x * 18, 142));
    		}
    	}
    	
    	@Override
    	public void addListener(IContainerListener listener) 
    	{
    		super.addListener(listener);
    		listener.sendAllWindowProperties(this, this.tileentity);
    	}
    	
    	@Override
    	public void detectAndSendChanges() 
    	{
    		super.detectAndSendChanges();
    		
    		for(int i = 0; i < this.listeners.size(); ++i) 
    		{
    			IContainerListener listener = (IContainerListener)this.listeners.get(i);
    			
    			if(this.cookTime != this.tileentity.getField(2)) listener.sendWindowProperty(this, 2, this.tileentity.getField(2));
    			if(this.burnTime != this.tileentity.getField(0)) listener.sendWindowProperty(this, 0, this.tileentity.getField(0));
    			if(this.currentBurnTime != this.tileentity.getField(1)) listener.sendWindowProperty(this, 1, this.tileentity.getField(1));
    			if(this.totalCookTime != this.tileentity.getField(3)) listener.sendWindowProperty(this, 3, this.tileentity.getField(3));
    		}
    		
    		this.cookTime = this.tileentity.getField(2);
    		this.burnTime = this.tileentity.getField(0);
    		this.currentBurnTime = this.tileentity.getField(1);
    		this.totalCookTime = this.tileentity.getField(3);
    		
    		
    		
    	}
    	
    	@Override
    	@SideOnly(Side.CLIENT)
    	public void updateProgressBar(int id, int data) 
    	{
    		this.tileentity.setField(id, data);
    	}
    	
    	@Override
    	public boolean canInteractWith(EntityPlayer playerIn) 
    	{
    		return this.tileentity.isUsableByPlayer(playerIn);
    	}
    	
    	@Override
    	public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) 
    	{
    		ItemStack stack = ItemStack.EMPTY;
    		Slot slot = (Slot)this.inventorySlots.get(index);
    		
    		if(slot != null && slot.getHasStack()) 
    		{
    			ItemStack stack1 = slot.getStack();
    			stack = stack1.copy();
    			
    			if(index == 3) 
    			{
    				if(!this.mergeItemStack(stack1, 4, 40, true)) return ItemStack.EMPTY;
    				slot.onSlotChange(stack1, stack);
    			}
    			else if(index != 2 && index != 1 && index != 0) 
    			{		
    				Slot slot1 = (Slot)this.inventorySlots.get(index + 1);
    				
    				if(!PrismallonFurnaceRecipes.getInstance().getPrismallonResult(stack1, slot1.getStack()).isEmpty())
    				{
    					if(!this.mergeItemStack(stack1, 0, 2, false)) 
    					{
    						return ItemStack.EMPTY;
    					}
    					else if(TileEntityNewDawnPrismallon.isItemFuel(stack1))
    					{
    						if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
    					}
    					else if(TileEntityNewDawnPrismallon.isItemFuel(stack1))
    					{
    						if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
    					}
    					else if(TileEntityNewDawnPrismallon.isItemFuel(stack1))
    					{
    						if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
    					}
    					else if(index >= 4 && index < 31)
    					{
    						if(!this.mergeItemStack(stack1, 31, 40, false)) return ItemStack.EMPTY;
    					}
    					else if(index >= 31 && index < 40 && !this.mergeItemStack(stack1, 4, 31, false))
    					{
    						return ItemStack.EMPTY;
    					}
    				}
    			} 
    			else if(!this.mergeItemStack(stack1, 4, 40, false)) 
    			{
    				return ItemStack.EMPTY;
    			}
    			if(stack1.isEmpty())
    			{
    				slot.putStack(ItemStack.EMPTY);
    			}
    			else
    			{
    				slot.onSlotChanged();
    
    			}
    			if(stack1.getCount() == stack.getCount()) return ItemStack.EMPTY;
    			slot.onTake(playerIn, stack1);
    		}
    		return stack;
    	}
    }

    GuiPrismallonFurnace.Java

    package com.booktail.anewdawn.blocks.machines;
    
    import com.booktail.anewdawn.util.Reference;
    
    import net.minecraft.client.gui.inventory.GuiContainer;
    import net.minecraft.client.renderer.GlStateManager;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.inventory.Container;
    import net.minecraft.util.ResourceLocation;
    
    public class GuiPrismallonFurnace extends GuiContainer{
    
    	private static final ResourceLocation TEXTURES = new ResourceLocation(Reference.MOD_ID + ":textures/gui/prismallonfurnace.png");
    	private final InventoryPlayer player;
    	private final TileEntityNewDawnPrismallon tileentity;
    	
    	
    	public GuiPrismallonFurnace(InventoryPlayer player, TileEntityNewDawnPrismallon tileentity) {
    		
    		super(new ContainerPrismallon(player, tileentity));
    		this.player = player;
    		this.tileentity = tileentity;
    
    	}
    	
    	@Override
    	protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
    		
    		String furnaceName = this.tileentity.getDisplayName().getUnformattedText();
    		this.fontRenderer.drawString(furnaceName, (this.xSize / 2 - this.fontRenderer.getStringWidth(furnaceName) / 2) + 3, 6, 4210752);
    		this.fontRenderer.drawString(this.player.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);
    	}
    	
    	@Override
    	protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
    
    		GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
    		this.mc.getTextureManager().bindTexture(TEXTURES);
    		this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);	
    		
    		if (TileEntityNewDawnPrismallon.isBurning(tileentity))
    		{
    			int k = getBurnLeftScale(13);
    			this.drawTexturedModalRect(this.guiLeft + 56, this.guiTop + 36 + 12 - k, 176, 12 - k, 14, k + 1);
    			
    		}
    		
    		int l = this.getCookedProgressScaled(24);
    		this.drawTexturedModalRect(this.guiLeft + 79, this.guiTop + 34, 176, 14, l + 1, 16);
    		
    		
    		
    	}
    
    	private int getBurnLeftScale(int pixels)
    	{
    		int i = this.tileentity.getField(1);
    		if (i == 0) i = 200;
    		return this.tileentity.getField(0) * pixels / i;
    	}
    	
    	private int getCookedProgressScaled(int pixels)
    	{
    		int i = this.tileentity.getField(2);
    		int j = this.tileentity.getField(3);
    		return i != 0 && j != 0 ? i * pixels / j : 0;
    
    	}
    	
    	
    }

     

    I am aware this code is absolutely spaghetti, I haven't really done any work on modding in a long time. Let me know if I missed anything, I'd appreciate the help!

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.