Jump to content

Recommended Posts

Posted

I been having trouble getting the items not to duplicate.

In my mod there's a liquid block (Hot Water) that has the property of cooking food when the food thrown into it. The cooking works but the liquid also creates extra unpickupable item that would disappear after a relog.

Here's the code of my main class and the hot water block class.

 

BlockHotWater Class

public class BlockHotWater extends BlockFluidClassic{

protected IIcon stillWater;
protected IIcon flowingWater;
protected World world;
protected Entity entity;
FoodList list = new FoodList();

public BlockHotWater(Fluid fluid, Material material) {
	super(fluid, material);
	setCreativeTab(CreativeTabs.tabMisc);
}

public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity)
    {
	if(!(entity instanceof EntityItem)){
        entity.attackEntityFrom(HotWater_Main.Boiled, 2.0F);
        WaterEffect(world,  x,  y,  z, 1);
	}
	if(entity instanceof EntityItem){
	CookingEffect(world, x, y , z, entity);
	}
    }

public void CookingEffect(World world, int x, int y, int z, Entity entity){
	if(((EntityItem)entity).getEntityItem().getItem() == Items.chicken) {
		WaterEffect(world, x, y, z, 2);
		entity.setDead();
		entity.entityDropItem(new ItemStack(Items.cooked_chicken), 0F);
	}
	if(((EntityItem)entity).getEntityItem().getItem() == Items.porkchop){
		WaterEffect(world, x, y, z, 2);
		entity.setDead();
		entity.entityDropItem(new ItemStack(Items.cooked_porkchop), 0F);
	}
        if(((EntityItem)entity).getEntityItem().getItem() == Items.beef){
        	WaterEffect(world, x, y, z, 2);
        	entity.setDead();
        	entity.entityDropItem(new ItemStack(Items.cooked_beef), 0F);
	}
        if(((EntityItem)entity).getEntityItem().getItem() == Items.potato || ((EntityItem)entity).getEntityItem().getItem() == Items.poisonous_potato){
        	WaterEffect(world, x, y, z, 2);
        	entity.setDead();
        	entity.entityDropItem(new ItemStack(Items.baked_potato), 0F);
	}
        if(((EntityItem)entity).getEntityItem().getItem() == Items.fish){
        	if(((EntityItem)entity).getEntityItem().getItemDamage() == 0){
        	 WaterEffect(world, x, y, z, 2);
        	 entity.setDead();
        	 entity.entityDropItem(new ItemStack(Items.cooked_fished, 1), 0F);
        	}
        	if(((EntityItem)entity).getEntityItem().getItemDamage() == 1){
           	 WaterEffect(world, x, y, z, 2);
           	 entity.setDead();
           	 entity.entityDropItem(new ItemStack(Items.cooked_fished, 1, 1), 0F);
           	}
        	
        }
}

 protected void WaterEffect(World world, int x, int y, int z, int type)
    {
	 world.playSoundEffect((float)x + 0.5F, (float)y + 0.5F, (float)z + 0.5F, "random.fizz", 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
        for(int l = 0; l < 8; l++)
        	if(type == 1){
        	world.spawnParticle("largesmoke", (double)x + Math.random(), (double)y + 1.2D, (double)z + Math.random(), 0.0D, 0.0D, 0.0D);
        	}
                if(type == 2){
                	world.spawnParticle("cloud", (double)x + Math.random(), (double)y + 1.2D, (double)z + Math.random(), 0.0D, 0.0D, 0.0D);
                }
    }	 

@Override
public IIcon getIcon (int side, int meta){
	return (IIcon) ((side == 0 || side == 1) ? stillWater : flowingWater);
}

    @Override
    public void registerBlockIcons(IIconRegister register) {
            stillWater = register.registerIcon("hot_water:hot_water_still");
            flowingWater = register.registerIcon("hot_water:hot_water_flow");
    }
   

}

 

Main Class

@Mod(name = "Hot Water Mod", modid = HotWater_Main.MODID, version = HotWater_Main.VERSION)
public class HotWater_Main {

public static final String MODID = "hot_water";
public static final String VERSION = "1.0";
private static final String Water_Name = "hot_water";
private static final String SuperLava_Name = "super_lava";
private static final String SpringWater_Name = "hot_spring_water";

public Fluid hotWater = new Fluid(Water_Name).setDensity(999).setTemperature(373).setViscosity(682);
public static Block BlockHotWater;
public static Block BlockSpringWater;
public static Item hot_water_bucket; 
public static DamageSource Boiled = new DamageSource("hot_water.boiled");

public Fluid superlava = new Fluid(SuperLava_Name).setDensity(999).setTemperature(6150).setViscosity(682);
public static Block BlockSuperLava;
public static Item superlava_bucket; 
public static DamageSource Melted = new DamageSource("hot_water.Melted").setFireDamage();
public static final Material Superlava = new MaterialLiquid(MapColor.tntColor);

public static Fluid springWater = new Fluid(SpringWater_Name).setDensity(999).setTemperature(373).setViscosity(682);

public static Item spring_water_bucket; 

public static BiomeGenBase BiomeHotSpring;

@EventHandler
public void PreInit(FMLPreInitializationEvent event){

	Configuration config = new Configuration(event.getSuggestedConfigurationFile());
    int BiomeID = config.get(Configuration.CATEGORY_GENERAL, "BiomeID", 35).getInt();

	FMLLog.info("[Hot Water] Registering the Hot Water, Spring Water and Super Lava Fluid");
	FluidRegistry.registerFluid(hotWater);
	FluidRegistry.registerFluid(superlava);
	FluidRegistry.registerFluid(springWater);
	FMLLog.info("[Hot Water] Hot Water, Spring Water and Super Lava fluid Registered");
	BlockSpringWater = new BlockSpringWater(springWater, Material.water).setBlockName(SpringWater_Name).setHardness(100F);
	FMLLog.info("[Hot Water] Registering the Hot Water, Spring Water and Super Lava Block");	
	BlockHotWater = new BlockHotWater(hotWater, Material.water).setBlockName(Water_Name).setHardness(100F);

	BlockSuperLava = new BlockSuperLava(superlava, Material.lava).setBlockName(SuperLava_Name).setHardness(100F).setLightLevel(10.0F);
	GameRegistry.registerBlock(BlockSuperLava, SuperLava_Name);
	GameRegistry.registerBlock(BlockHotWater, Water_Name);
	GameRegistry.registerBlock(BlockSpringWater, SpringWater_Name);
	FMLLog.info("[Hot Water] Hot Water, Spring Water and Super Lava Block Registered");

	FMLLog.info("[Hot Water] Registering Hot Water, Spring Water and Super Lava Bucket");
	hot_water_bucket = new ItemBucket(BlockHotWater).setTextureName("hot_water:bucket_hot_water").setUnlocalizedName("bucket_hot_water");
	GameRegistry.registerItem(hot_water_bucket, "bucket_hot_water", MODID);
	FluidContainerRegistry.registerFluidContainer(FluidRegistry.getFluidStack(Water_Name, FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(hot_water_bucket), new ItemStack(Items.bucket));

	superlava_bucket = new ItemBucket(BlockSuperLava).setTextureName("bucket_lava").setUnlocalizedName("bucket_superlava");
	GameRegistry.registerItem(superlava_bucket, "bucket_superlava", MODID);
	FluidContainerRegistry.registerFluidContainer(FluidRegistry.getFluidStack(SuperLava_Name, FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(superlava_bucket), new ItemStack(Items.bucket));

	spring_water_bucket = new ItemBucket(BlockSpringWater).setTextureName("hot_water:bucket_hot_spring_water").setUnlocalizedName("bucket_spring_water");
	GameRegistry.registerItem(spring_water_bucket, "bucket_spring_water", MODID);
	FluidContainerRegistry.registerFluidContainer(FluidRegistry.getFluidStack(SpringWater_Name, FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(spring_water_bucket), new ItemStack(Items.bucket));
	FMLLog.info("[Hot Water] Hot Water Bucket, Spring Water and Super Lava Registered");

	FMLLog.info("[Hot Water] Registering Buildcraft's BucketFill Event");
	BucketHandler.INSTANCE.buckets.put(BlockHotWater, hot_water_bucket);
    BucketHandler.INSTANCE.buckets.put(BlockSuperLava, superlava_bucket);
    BucketHandler.INSTANCE.buckets.put(BlockSpringWater, spring_water_bucket);
	MinecraftForge.EVENT_BUS.register(BucketHandler.INSTANCE);
    FMLLog.info("[Hot Water] Buildcraft's BucketFill Event Registered");
    
    config.load();
    
    FMLLog.info("[Hot Water] Adding new Spring Biome (BECUASE WORLDGEN IS HARD D:)");
    BiomeHotSpring = new BiomeHotSpring(BiomeID).setEnableSnow().setBiomeName("Hot Springs").setHeight(new Height(0F, 0F));
    BiomeDictionary.registerBiomeType(BiomeHotSpring, Type.FROZEN);
    FMLLog.info("[Hot Water] Spring Biome Added");

    config.save();
    
	FMLLog.info("[Hot Water] Registering Cooking Recipes and Fuel");
	GameRegistry.addSmelting(Items.water_bucket, new ItemStack(hot_water_bucket), 0.3F);
	GameRegistry.addSmelting(Items.lava_bucket, new ItemStack(superlava_bucket), 0.5F);
	GameRegistry.registerFuelHandler(new FuelHandler());
	FMLLog.info("[Hot Water] Cooking Recipes and Fuel Registered");

}

}

A video of it to help you see the problem

[embed=425,349]

[/embed]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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