Start on fluid system
|
@ -17,6 +17,7 @@ import techreborn.compat.CompatManager;
|
||||||
import techreborn.compat.recipes.RecipeManager;
|
import techreborn.compat.recipes.RecipeManager;
|
||||||
import techreborn.config.ConfigTechReborn;
|
import techreborn.config.ConfigTechReborn;
|
||||||
import techreborn.init.ModBlocks;
|
import techreborn.init.ModBlocks;
|
||||||
|
import techreborn.init.ModFluids;
|
||||||
import techreborn.init.ModItems;
|
import techreborn.init.ModItems;
|
||||||
import techreborn.init.ModRecipes;
|
import techreborn.init.ModRecipes;
|
||||||
import techreborn.lib.ModInfo;
|
import techreborn.lib.ModInfo;
|
||||||
|
@ -55,6 +56,8 @@ public class Core {
|
||||||
ModBlocks.init();
|
ModBlocks.init();
|
||||||
// Register ModItems
|
// Register ModItems
|
||||||
ModItems.init();
|
ModItems.init();
|
||||||
|
// Register Fluids
|
||||||
|
ModFluids.init();
|
||||||
// Recipes
|
// Recipes
|
||||||
ModRecipes.init();
|
ModRecipes.init();
|
||||||
//Client only init, needs to be done before parts system
|
//Client only init, needs to be done before parts system
|
||||||
|
|
57
src/main/java/techreborn/blocks/fluid/BlockFluidBase.java
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
package techreborn.blocks.fluid;
|
||||||
|
|
||||||
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||||
|
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;
|
||||||
|
import techreborn.client.TechRebornCreativeTabMisc;
|
||||||
|
import techreborn.lib.ModInfo;
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
public class BlockFluidBase extends BlockFluidClassic{
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
protected IIcon stillIcon;
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
protected IIcon flowingIcon;
|
||||||
|
|
||||||
|
public BlockFluidBase(Fluid fluid, Material material)
|
||||||
|
{
|
||||||
|
super(fluid, material);
|
||||||
|
setCreativeTab(TechRebornCreativeTabMisc.instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IIcon getIcon(int side, int meta)
|
||||||
|
{
|
||||||
|
return (side == 0 || side == 1) ? stillIcon : flowingIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
@Override
|
||||||
|
public void registerBlockIcons(IIconRegister register)
|
||||||
|
{
|
||||||
|
stillIcon = register.registerIcon(ModInfo.MOD_ID.toLowerCase() + ":" + "fluids/" + getUnlocalizedName().substring(16) + "_still");
|
||||||
|
flowingIcon = register.registerIcon(ModInfo.MOD_ID.toLowerCase() + ":" + "fluids/" + getUnlocalizedName().substring(16) + "_flowing");
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package techreborn.blocks.fluid;
|
||||||
|
|
||||||
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
|
||||||
|
public class BlockFluidBerylium extends BlockFluidBase{
|
||||||
|
|
||||||
|
public BlockFluidBerylium(Fluid fluid, Material material)
|
||||||
|
{
|
||||||
|
super(fluid, material);
|
||||||
|
setBlockName("techreborn.berylium");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
29
src/main/java/techreborn/init/ModFluids.java
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package techreborn.init;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
|
import techreborn.blocks.fluid.BlockFluidBerylium;
|
||||||
|
import techreborn.lib.ModInfo;
|
||||||
|
import techreborn.util.BucketHandler;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
import net.minecraftforge.fluids.FluidRegistry;
|
||||||
|
|
||||||
|
public class ModFluids {
|
||||||
|
|
||||||
|
public static Fluid fluidberylium = new Fluid("fluidberylium");
|
||||||
|
public static Block BlockFluidBerylium;
|
||||||
|
|
||||||
|
public static void init()
|
||||||
|
{
|
||||||
|
FluidRegistry.registerFluid(fluidberylium);
|
||||||
|
BlockFluidBerylium = new BlockFluidBerylium(fluidberylium, Material.water);
|
||||||
|
GameRegistry.registerBlock(BlockFluidBerylium, ModInfo.MOD_ID + "_" + BlockFluidBerylium.getUnlocalizedName().substring(5));
|
||||||
|
fluidberylium.setUnlocalizedName(BlockFluidBerylium.getUnlocalizedName());
|
||||||
|
|
||||||
|
|
||||||
|
BucketHandler.INSTANCE.buckets.put(ModFluids.BlockFluidBerylium, ModItems.cells);
|
||||||
|
MinecraftForge.EVENT_BUS.register(BucketHandler.INSTANCE);
|
||||||
|
}
|
||||||
|
}
|
53
src/main/java/techreborn/util/BucketHandler.java
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
package techreborn.util;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.eventhandler.Event.Result;
|
||||||
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class BucketHandler {
|
||||||
|
|
||||||
|
public static BucketHandler INSTANCE = new BucketHandler();
|
||||||
|
public Map<Block, Item> buckets = new HashMap<Block, Item>();
|
||||||
|
|
||||||
|
private BucketHandler()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@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(bucket);
|
||||||
|
} else
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 144 B After Width: | Height: | Size: 144 B |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 145 B After Width: | Height: | Size: 145 B |
Before Width: | Height: | Size: 145 B After Width: | Height: | Size: 145 B |
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 144 B After Width: | Height: | Size: 144 B |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 144 B After Width: | Height: | Size: 144 B |
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.5 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 144 B After Width: | Height: | Size: 144 B |
Before Width: | Height: | Size: 144 B After Width: | Height: | Size: 144 B |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.5 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 144 B After Width: | Height: | Size: 144 B |
Before Width: | Height: | Size: 8 KiB After Width: | Height: | Size: 8 KiB |