Add liquid light
This commit is contained in:
parent
ea34f55a12
commit
a6d21ce33a
9 changed files with 151 additions and 1 deletions
135
java/net/universe_factory/minecraft/test/LiquidLight.java
Normal file
135
java/net/universe_factory/minecraft/test/LiquidLight.java
Normal file
|
@ -0,0 +1,135 @@
|
|||
package net.universe_factory.minecraft.test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBucket;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.FillBucketEvent;
|
||||
import net.minecraftforge.fluids.BlockFluidClassic;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import cpw.mods.fml.common.eventhandler.Event.Result;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class LiquidLight extends Fluid {
|
||||
private class BlockLiquidLight extends BlockFluidClassic {
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected IIcon stillIcon;
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected IIcon flowingIcon;
|
||||
|
||||
public BlockLiquidLight() {
|
||||
super(LiquidLight.this, Material.water);
|
||||
setCreativeTab(CreativeTabs.tabMisc);
|
||||
}
|
||||
|
||||
@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(Test.MODID + ":liquid_light_still");
|
||||
flowingIcon = register.registerIcon(Test.MODID + ":liquid_light_flow");
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
private class ItemBucketLight extends ItemBucket {
|
||||
public ItemBucketLight(Block block) {
|
||||
super(block);
|
||||
setUnlocalizedName("bucket_light");
|
||||
setContainerItem(Items.bucket);
|
||||
setTextureName(Test.MODID + ":bucket_light");
|
||||
}
|
||||
}
|
||||
|
||||
public static class BucketHandler {
|
||||
|
||||
public static BucketHandler INSTANCE = new BucketHandler();
|
||||
public Map<Block, Item> buckets = new HashMap<Block, Item>();
|
||||
|
||||
public BucketHandler() {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public LiquidLight() {
|
||||
super("liquid_light");
|
||||
|
||||
setDensity(1);
|
||||
setLuminosity(15);
|
||||
setViscosity(1000);
|
||||
}
|
||||
|
||||
public void register() {
|
||||
FluidRegistry.registerFluid(this);
|
||||
|
||||
BlockLiquidLight block = new BlockLiquidLight();
|
||||
|
||||
GameRegistry.registerBlock(block, "liquid_light");
|
||||
setUnlocalizedName(block.getUnlocalizedName());
|
||||
|
||||
ItemBucketLight bucket = new ItemBucketLight(block);
|
||||
GameRegistry.registerItem(bucket, "bucket_light");
|
||||
FluidContainerRegistry.registerFluidContainer(this, new ItemStack(bucket), new ItemStack(Items.bucket));
|
||||
|
||||
BucketHandler.INSTANCE.buckets.put(block, bucket);
|
||||
}
|
||||
}
|
|
@ -184,6 +184,8 @@ public class Test {
|
|||
|
||||
public static final ExtensibleBiomeDecorator biomeDecorator = new ExtensibleBiomeDecorator();
|
||||
|
||||
public static final LiquidLight liquidLight = new LiquidLight();
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLInitializationEvent event) {
|
||||
MinecraftForge.TERRAIN_GEN_BUS.register(new TerrainGenHandler());
|
||||
|
@ -211,6 +213,8 @@ public class Test {
|
|||
GameRegistry.addRecipe(new ItemStack(glowfoo, 4, i), "###", "#X#", "###", '#', new ItemStack(Blocks.stained_glass_pane, 1, i), 'X',
|
||||
Blocks.redstone_block);
|
||||
|
||||
liquidLight.register();
|
||||
|
||||
biomeDecorator.registerTree(new ExtensibleBiomeDecorator.Tree() {
|
||||
@Override
|
||||
public Entry<WorldGenAbstractTree, Float> replaceTree(World world, BiomeGenBase biome, Random random, int x, int y, int z,
|
||||
|
|
|
@ -40,4 +40,7 @@ tile.glowfoo.yellow.name=Yellow Light
|
|||
tile.glowfoo.lightBlue.name=Light Blue Light
|
||||
tile.glowfoo.magenta.name=Magenta Light
|
||||
tile.glowfoo.orange.name=Orange Light
|
||||
tile.glowfoo.white.name=White Light
|
||||
|
||||
|
||||
tile.liquid_light.name=Liquid Light
|
||||
item.bucket_light.name=Light Bucket
|
Binary file not shown.
After Width: | Height: | Size: 8.3 KiB |
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"animation": {}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 9.9 KiB |
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"animation": {
|
||||
"frametime": 2
|
||||
}
|
||||
}
|
BIN
resources/assets/neoraider_test/textures/items/bucket_light.png
Normal file
BIN
resources/assets/neoraider_test/textures/items/bucket_light.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 569 B |
BIN
resources/assets/neoraider_test/textures/items/bucket_light.xcf
Normal file
BIN
resources/assets/neoraider_test/textures/items/bucket_light.xcf
Normal file
Binary file not shown.
Reference in a new issue