Jump to content

Recommended Posts

Posted

For the past few weeks, I've been trying to add a new liquid into Minecraft. my only problem is that, while I can pick it up in a standard bucket, I cant place it back down. I have yet to find the bug in my code, and its driving me crazy.

 

Here is all the code related to the liquid:

 

Main Class File

 

package assets.wristwatch1_rainbowwater;

 

@Mod( modid = rainbowwater.modid, name = "Rainbow Water", version = "1.1.1") //mod details

 

 

public class rainbowwater

 

{

public static final String modid = "wristwatch1_rainbowwater"; //sets MODID

 

@Instance ("wristwatch1_rainbowwater")

public static rainbowwater instance;

 

@SidedProxy (clientSide = "assets.wristwatch1_rainbowwater.ClientProxyRainbowWater", serverSide = "mod.wristwatch1_rainbowwater.commonProxyRainbowWater")

public static CommonProxyRainbowWater proxy; //sets the proxys

 

 

 

//Fluids (Tells the code there is a fluid)

 

public static Fluid ProtoSpectra;

 

 

//Blocks

 

public static Block BlockProtoSpectra;

 

 

 

//Items (you know what these are:) )

 

public static Item ProtoSpectraBucket;

 

 

//Armour

 

 

 

//CreativeTabs

 

public static CreativeTabs tabFluids = new TabFluids(CreativeTabs.getNextID(),"Wristwatch1tabFluids"); //Creates Creative tab

 

@EventHandler public void preInit(FMLPreInitializationEvent evt) {

 

proxy.registerRenderThings(); //Without this, buckets wont fill

 

MinecraftForge.EVENT_BUS.register(new ProtoSpectraBucketHandler());

 

 

}

 

 

//@EventHandler

  //public void load(FMLInitializationEvent event)

  {

//Fluids (Links to the class files)

 

ProtoSpectra = new Fluid ("ProtoSpectra").setDensity(10).setViscosity(1000);

 

  FluidRegistry.registerFluid(ProtoSpectra);

 

 

//Blocks (links to the class files and sets BLOCKID's and unlocalized names)

 

BlockProtoSpectra = new BlockProtoSpectra(ProtoSpectra, ProtoSpectra, Material.water);//.setBlockName("BlockProtoSpectra");  //2382

 

 

//Items (Links to the class files and sets ITEMID'S, unlocalized names and container items)

 

ProtoSpectraBucket = new ItemProtoSpectraBucket(ProtoSpectra).setUnlocalizedName("ItemProtoSpectraBucket").setContainerItem(Items.bucket);  //3857, BlockProtoSpectra.blockID

 

 

 

//Game Registry (Registers the blocks and items to the game)

 

//Blocks

 

GameRegistry.registerBlock(BlockProtoSpectra, "ProtoSpectra");

 

 

//Items

 

GameRegistry.registerItem(ProtoSpectraBucket, "ProtoSpectraBucket");

 

 

 

//Language Registry

 

//Blocks

 

//Fluid (Gives the fluids their in-game names)

 

//LanguageRegistry.addName(BlockProtoSpectra, "Prototype Spectra");

 

 

//Items (Gives the items their in-game names)

 

//LanguageRegistry.addName(ProtoSpectraBucket, "Bucket of Prototype Spectra");

 

 

//Armour

 

 

//FluidRegistry

 

ProtoSpectra.setUnlocalizedName(BlockProtoSpectra.getUnlocalizedName());

 

 

 

//ContainerRegistery (Links the bucket to the fluid)

 

//FluidContainerRegistry.registerFluidContainer(new FluidContainerData(FluidRegistry.getFluidStack(rainbowwater.ProtoSpectra.getName(), FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(rainbowwater.ProtoSpectraBucket), new ItemStack(Items.bucket)));

 

 

 

ProtoSpectraBucketHandler.INSTANCE.buckets.put(BlockProtoSpectra, ProtoSpectraBucket);

MinecraftForge.EVENT_BUS.register(ProtoSpectraBucketHandler.INSTANCE);

 

  }

/* @ForgeSubscribe

@SideOnly(Side.CLIENT)

public void textureHook(TextureStitchEvent.Post event) {

if (event.map.textureType == 0) {

WhiteSpectra.setIcons(rainbowwater.BlockWhiteSpectra.getBlockTextureFromSide(1));

}

}*/

 

 

{

//EventBus

MinecraftForge.EVENT_BUS.register(this); //Closes the stuff

}

 

@EventHandler public void postInit(FMLPostInitializationEvent evt) {

 

FluidContainerRegistry.registerFluidContainer(new FluidContainerData(FluidRegistry.getFluidStack("protospectra", FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(rainbowwater.ProtoSpectraBucket), new ItemStack(Items.bucket)));

 

}

}

 

 

 

 

 

 

ProtoSpectra File:

 

package assets.wristwatch1_rainbowwater.fluid;

 

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLiving;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.world.World;

import net.minecraftforge.fluids.Fluid;

import net.minecraftforge.fluids.FluidRegistry;

 

 

public class ProtoSpectra extends Fluid

{

public ProtoSpectra()

{

super("ProtoSpectra");

setDensity(10); // How tick the fluid is, affects movement inside the liquid.

setViscosity(1000); // How fast the fluid flows.

setUnlocalizedName("ProtoSpectra");

FluidRegistry.registerFluid(this); // Registering inside it self, keeps things neat :)

}

 

}

 

 

 

 

Block ProtoSpectra

 

package assets.wristwatch1_rainbowwater.block;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import assets.wristwatch1_rainbowwater.rainbowwater;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLiving;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Blocks;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.util.IIcon;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

import net.minecraftforge.fluids.BlockFluidClassic;

import net.minecraftforge.fluids.Fluid;

 

 

public class BlockProtoSpectra extends BlockFluidClassic {

 

    @SideOnly(Side.CLIENT)

    protected IIcon stillIcon;

    @SideOnly(Side.CLIENT)

    protected IIcon flowingIcon;

 

   

    public BlockProtoSpectra(Fluid fluid, Fluid protoSpectra, Material material) {

            super(fluid, material);

            setBlockName("ProtoSpectra");

            setCreativeTab(rainbowwater.tabFluids);

    }

    /*

    @Override

    public IIcon getIcon(int side, int meta) {

            return (side == 0 || side == 1)? stillIcon : flowingIcon;

    }

   

    @SideOnly(Side.CLIENT)

    @Override

    public void registerBlockIcons(IIconRegister iconregister) {

            this.stillIcon = iconregister.registerIcon("wristwatch1_rainbowwater:BlockWhiteSpectraStill");

            this.flowingIcon = iconregister.registerIcon("wristwatch1_rainbowwater:BlockWhiteSpectraFlowing");

    }*/

    @Override

public boolean canDisplace(IBlockAccess world, int x, int y, int z) {

if (world.getBlock(x, y, z).getMaterial().isLiquid())

return false;

return super.canDisplace(world, x, y, z);

}

 

 

@Override

public boolean displaceIfPossible(World world, int x, int y, int z) {

if (world.getBlock(x, y, z).getMaterial().isLiquid())

return false;

return super.displaceIfPossible(world, x, y, z);

}

 

 

// Use Register Icon as usual to get the block's icon.

// If you want you can reuse the water texture and change the color of it by doing as I have below:

@Override

@SideOnly(Side.CLIENT)

public IIcon getIcon(int side, int meta)

{

return Blocks.water.getIcon(side, meta);

}

@Override

public int colorMultiplier(IBlockAccess iblockaccess, int x, int y, int z)

{

return 0x66FF00; // HEX color code as indicated by the 0x in front. This is a greenish color.

}

 

@Override

@SideOnly(Side.CLIENT)

public void onEntityCollidedWithBlock(World world, int i, int j, int k, Entity entity)//when an entity steps into the liquid

{

if (entity instanceof EntityPlayer)

{       

((EntityPlayer) entity).addPotionEffect(new PotionEffect(Potion.weakness.getId(),1200, 1));//allows the potion affect to effect players

if (entity instanceof EntityLiving)

{       

((EntityLiving) entity).addPotionEffect(new PotionEffect(Potion.weakness.getId(),1200, 1));//allows the potion affect to effect mobs

}

}

 

 

 

 

 

 

ProtoSpectra Bucket

 

package assets.wristwatch1_rainbowwater.item;

 

import net.minecraft.block.Block;

import net.minecraft.client.renderer.texture.IIconRegister;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemBucket;

import net.minecraft.item.ItemStack;

import net.minecraft.world.World;

import net.minecraftforge.fluids.Fluid;

import assets.wristwatch1_rainbowwater.rainbowwater;

 

public class ItemProtoSpectraBucket extends ItemBucket

{

public ItemProtoSpectraBucket(Fluid fluid)

{

  super(null);

  this.setCreativeTab(rainbowwater.tabFluids);

  this.setContainerItem(Items.bucket);

}

 

 

public void registerIcons(IIconRegister par1IconRegister)

 

{

 

    this.itemIcon = par1IconRegister.registerIcon("wristwatch1_rainbowwater:ItemGreenSpectraBucket");

 

}

 

public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)

{

par3EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Items.glass_bottle,3));

}

 

}

 

 

 

 

 

ProtoSpectra Bucket Handler

 

package assets.wristwatch1_rainbowwater.buckethandlers;

 

import java.util.HashMap;

import java.util.Map;

 

import assets.wristwatch1_rainbowwater.rainbowwater;

import net.minecraft.block.Block;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.MovingObjectPosition;

import net.minecraft.world.World;

import net.minecraftforge.event.entity.player.FillBucketEvent;

import cpw.mods.fml.common.eventhandler.Event.Result;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;

 

public class ProtoSpectraBucketHandler {

 

    public static ProtoSpectraBucketHandler INSTANCE = new ProtoSpectraBucketHandler();

    public Map<Block, Item> buckets = new HashMap<Block, Item>();

 

    public ProtoSpectraBucketHandler() {

    }

 

    @SubscribeEvent

    public void onBucketFill(FillBucketEvent event) {

 

            ItemStack result = fillCustomBucket(event.world, event.target);

 

            if (result == null)

                    return;

 

            event.result = result;

            event.setResult(Result.ALLOW);

    }

 

    private ItemStack fillCustomBucket(World world, MovingObjectPosition pos) {

 

            Block block = world.getBlock(pos.blockX, pos.blockY, pos.blockZ);

 

            Item bucket = buckets.get(block);

            if (bucket != null && world.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ) == 0) {

                    world.setBlockToAir(pos.blockX, pos.blockY, pos.blockZ);

                   

                    return new ItemStack(rainbowwater.ProtoSpectraBucket);

            } else

                    return null;

 

    }

}

 

 

 

 

 

Any help would be Greatly Appreciated.

Posted

Look at your Bucket constructor, especially what you pass to the super constructor. Now think :P

 

........

 

My god, I am an idiot.

Once you pointed that out, took me 5 mins to fix what has had me buggered for a month and a half.

 

Thank you! ;D

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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