Compare commits
3 commits
e3e9598fc5
...
e85166666f
Author | SHA1 | Date | |
---|---|---|---|
e85166666f | |||
eb5c03dda3 | |||
039a7d7d9e |
50 changed files with 643 additions and 1014 deletions
|
@ -16,14 +16,16 @@ import client.renderer.texture.TextureMap;
|
|||
import client.renderer.tileentity.TileEntityItemStackRenderer;
|
||||
import common.block.Block;
|
||||
import common.block.Material;
|
||||
import common.block.liquid.BlockDynamicLiquid;
|
||||
import common.block.liquid.BlockLiquid;
|
||||
import common.block.liquid.BlockStaticLiquid;
|
||||
import common.collect.Maps;
|
||||
import common.init.BlockRegistry;
|
||||
import common.init.FluidRegistry;
|
||||
import common.item.ItemStack;
|
||||
import common.util.BlockPos;
|
||||
import common.util.ExtMath;
|
||||
import common.util.Facing;
|
||||
import common.util.Pair;
|
||||
import common.util.Vec3i;
|
||||
import common.world.IBlockAccess;
|
||||
import common.world.IWorldAccess;
|
||||
|
@ -406,12 +408,11 @@ public class BlockRenderer
|
|||
private void initAtlasSprites()
|
||||
{
|
||||
TextureMap texturemap = Client.CLIENT.getTextureMapBlocks();
|
||||
for(int z = 0; z < FluidRegistry.getNumFluids(); z++) {
|
||||
BlockLiquid block = FluidRegistry.getStaticBlock(z);
|
||||
String name = BlockRegistry.getNameFromBlock(block).toString();
|
||||
for(Pair<BlockStaticLiquid, BlockDynamicLiquid> liquid : BlockLiquid.LIQUIDS) {
|
||||
String name = BlockRegistry.getNameFromBlock(liquid.first());
|
||||
TextureAtlasSprite[] sprites = new TextureAtlasSprite[] {texturemap.getAtlasSprite("blocks/" + name + "_still"), texturemap.getAtlasSprite("blocks/" + name + "_flow")};
|
||||
this.fluids.put(FluidRegistry.getFluidBlock(z), sprites);
|
||||
this.fluids.put(block, sprites);
|
||||
this.fluids.put(liquid.second(), sprites);
|
||||
this.fluids.put(liquid.first(), sprites);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,16 +9,19 @@ import java.util.Set;
|
|||
|
||||
import client.renderer.texture.TextureAtlasSprite;
|
||||
import client.renderer.texture.TextureMap;
|
||||
import common.block.liquid.BlockDynamicLiquid;
|
||||
import common.block.liquid.BlockLiquid;
|
||||
import common.block.liquid.BlockStaticLiquid;
|
||||
import common.collect.Lists;
|
||||
import common.collect.Maps;
|
||||
import common.collect.Sets;
|
||||
import common.init.BlockRegistry;
|
||||
import common.init.FluidRegistry;
|
||||
import common.init.ItemRegistry;
|
||||
import common.item.Item;
|
||||
import common.model.ModelRotation;
|
||||
import common.util.Facing;
|
||||
import common.util.IRegistry;
|
||||
import common.util.Pair;
|
||||
import common.util.RegistrySimple;
|
||||
import common.world.State;
|
||||
|
||||
|
@ -37,8 +40,8 @@ public abstract class ModelBakery
|
|||
public static final ModelBlock MODEL_ENTITY = (ModelBlock)new ModelBlock(null).add().d("");
|
||||
|
||||
static {
|
||||
for(int z = 0; z < FluidRegistry.getNumFluids(); z++) {
|
||||
String name = BlockRegistry.getNameFromBlock(FluidRegistry.getStaticBlock(z)).toString();
|
||||
for(Pair<BlockStaticLiquid, BlockDynamicLiquid> liquid : BlockLiquid.LIQUIDS) {
|
||||
String name = BlockRegistry.getNameFromBlock(liquid.first());
|
||||
BUILTINS.add("blocks/" + name + "_flow");
|
||||
BUILTINS.add("blocks/" + name + "_still");
|
||||
}
|
||||
|
|
|
@ -8,11 +8,8 @@ import java.util.Set;
|
|||
import client.renderer.texture.TextureAtlasSprite;
|
||||
import client.renderer.texture.TextureMap;
|
||||
import common.block.Block;
|
||||
import common.block.liquid.BlockLiquid;
|
||||
import common.collect.Maps;
|
||||
import common.init.BlockRegistry;
|
||||
import common.init.Blocks;
|
||||
import common.init.FluidRegistry;
|
||||
import common.properties.Property;
|
||||
import common.util.IRegistry;
|
||||
import common.world.State;
|
||||
|
@ -22,7 +19,6 @@ public class ModelManager
|
|||
private IRegistry<String, IBakedModel> modelRegistry;
|
||||
private final TextureMap texMap;
|
||||
private final Map<State, IBakedModel> bakedModelStore = Maps.<State, IBakedModel>newIdentityHashMap();
|
||||
private final Map<Block, String> liquidMap = Maps.<Block, String>newIdentityHashMap();
|
||||
private final Map<Block, StateMap> mappers = Maps.<Block, StateMap>newIdentityHashMap();
|
||||
private final Set<Block> builtin = Collections.newSetFromMap(Maps.<Block, Boolean>newIdentityHashMap());
|
||||
private IBakedModel defaultModel;
|
||||
|
@ -76,35 +72,21 @@ public class ModelManager
|
|||
public TextureAtlasSprite getTexture(State state)
|
||||
{
|
||||
Block block = state.getBlock();
|
||||
IBakedModel ibakedmodel = this.getModelForState(state);
|
||||
IBakedModel model = this.getModelForState(state);
|
||||
|
||||
if (ibakedmodel == null || ibakedmodel == this.defaultModel)
|
||||
if (model == null || model == this.defaultModel)
|
||||
{
|
||||
if (block == Blocks.wall_sign || block == Blocks.sign || block == Blocks.chest || block == Blocks.trapped_chest || block == Blocks.banner || block == Blocks.wall_banner)
|
||||
{
|
||||
return this.texMap.getAtlasSprite("blocks/oak_planks");
|
||||
}
|
||||
|
||||
if (block == Blocks.floor_portal)
|
||||
{
|
||||
return this.texMap.getAtlasSprite("blocks/obsidian");
|
||||
}
|
||||
|
||||
if (block.getMaterial().isLiquid())
|
||||
{
|
||||
String texture = this.liquidMap.get(block);
|
||||
if(texture == null)
|
||||
this.liquidMap.put(block, texture = "blocks/" + BlockRegistry.getNameFromBlock(FluidRegistry.getStaticBlock(FluidRegistry.getFluidMeta((BlockLiquid)block))) + "_still");
|
||||
return this.texMap.getAtlasSprite(texture);
|
||||
}
|
||||
String tex = block.getFallbackTexture();
|
||||
if(tex != null)
|
||||
return this.texMap.getAtlasSprite("blocks/" + tex);
|
||||
}
|
||||
|
||||
if (ibakedmodel == null)
|
||||
if (model == null)
|
||||
{
|
||||
ibakedmodel = this.defaultModel;
|
||||
model = this.defaultModel;
|
||||
}
|
||||
|
||||
return ibakedmodel.getBaseTexture();
|
||||
return model.getBaseTexture();
|
||||
}
|
||||
|
||||
public IBakedModel getModelForState(State state)
|
||||
|
|
|
@ -15,7 +15,6 @@ import common.block.Block;
|
|||
import common.collect.Lists;
|
||||
import common.collect.Maps;
|
||||
import common.init.BlockRegistry;
|
||||
import common.init.FluidRegistry;
|
||||
import common.log.Log;
|
||||
import common.model.TextureAnimation;
|
||||
|
||||
|
@ -45,21 +44,15 @@ public class TextureMap extends Texture
|
|||
for(Block block : BlockRegistry.REGISTRY) {
|
||||
block.getAnimatedTextures(map);
|
||||
}
|
||||
for(int z = 0; z < FluidRegistry.getNumFluids(); z++) {
|
||||
map.put("blocks/" + BlockRegistry.getNameFromBlock(FluidRegistry.getStaticBlock(z)) + "_still",
|
||||
FluidRegistry.getStaticAnim(z));
|
||||
map.put("blocks/" + BlockRegistry.getNameFromBlock(FluidRegistry.getStaticBlock(z)) + "_flow",
|
||||
FluidRegistry.getFluidAnim(z));
|
||||
}
|
||||
for(Entry<String, Object> entry : map.entrySet()) {
|
||||
if(entry.getValue() instanceof Integer) {
|
||||
this.animTextures.put(entry.getKey(), (Integer)entry.getValue());
|
||||
this.animTextures.put("blocks/" + entry.getKey(), (Integer)entry.getValue());
|
||||
}
|
||||
else {
|
||||
Class<? extends TextureTicked> clazz = anim.get((TextureAnimation)entry.getValue());
|
||||
if(clazz == null)
|
||||
throw new RuntimeException("Animation '" + entry.getValue() + "' existiert nicht");
|
||||
this.tickedTextures.put(entry.getKey(), clazz);
|
||||
this.tickedTextures.put("blocks/" + entry.getKey(), clazz);
|
||||
}
|
||||
}
|
||||
map.clear();
|
||||
|
|
|
@ -1011,4 +1011,8 @@ public class Block {
|
|||
public final int getEncouragement() {
|
||||
return this.encouragement;
|
||||
}
|
||||
|
||||
public String getFallbackTexture() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,6 +152,10 @@ public class BlockFloorPortal extends Block
|
|||
}
|
||||
|
||||
public void getAnimatedTextures(Map<String, Object> map) {
|
||||
map.put("blocks/floor_portal", 5);
|
||||
map.put("floor_portal", 5);
|
||||
}
|
||||
|
||||
public String getFallbackTexture() {
|
||||
return "obsidian";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -293,7 +293,7 @@ public class BlockPortal extends Block
|
|||
}
|
||||
|
||||
public void getAnimatedTextures(Map<String, Object> map) {
|
||||
map.put("blocks/portal", 1);
|
||||
map.put("portal", 1);
|
||||
}
|
||||
|
||||
// public BlockPattern.PatternHelper func_181089_f(World p_181089_1_, BlockPos p_181089_2_)
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package common.block.liquid;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import common.block.Block;
|
||||
import common.block.Material;
|
||||
import common.block.artificial.BlockDoor;
|
||||
import common.init.BlockRegistry;
|
||||
import common.init.Blocks;
|
||||
import common.rng.Random;
|
||||
import common.util.BlockPos;
|
||||
|
@ -19,16 +21,25 @@ public class BlockDynamicLiquid extends BlockLiquid
|
|||
{
|
||||
private final boolean infinite;
|
||||
int adjacentSourceBlocks;
|
||||
private BlockStaticLiquid staticBlock;
|
||||
|
||||
public BlockDynamicLiquid(Material materialIn, boolean infinite, boolean opaque, int rate)
|
||||
public BlockDynamicLiquid(Material materialIn, boolean infinite, boolean opaque, int rate, Object animation)
|
||||
{
|
||||
super(materialIn, true, opaque, rate);
|
||||
super(materialIn, true, opaque, rate, animation);
|
||||
this.infinite = infinite;
|
||||
}
|
||||
|
||||
void setStaticBlock(BlockStaticLiquid block) {
|
||||
this.staticBlock = block;
|
||||
}
|
||||
|
||||
public BlockStaticLiquid getStaticBlock() {
|
||||
return this.staticBlock;
|
||||
}
|
||||
|
||||
private void placeStaticBlock(World worldIn, BlockPos pos, State currentState)
|
||||
{
|
||||
worldIn.setState(pos, getStaticBlock(this).getState().withProperty(LEVEL, currentState.getValue(LEVEL)), 2);
|
||||
worldIn.setState(pos, this.staticBlock.getState().withProperty(LEVEL, currentState.getValue(LEVEL)), 2);
|
||||
}
|
||||
|
||||
public void updateTick(AWorldServer worldIn, BlockPos pos, State state, Random rand)
|
||||
|
@ -292,7 +303,7 @@ public class BlockDynamicLiquid extends BlockLiquid
|
|||
private boolean canFlowInto(World worldIn, BlockPos pos, State state)
|
||||
{
|
||||
Material material = state.getBlock().getMaterial();
|
||||
return (this.material == Material.LAVA || !(state.getBlock() instanceof BlockLiquid) || (state.getBlock() instanceof BlockStaticLiquid ? BlockLiquid.getFlowingBlock((BlockStaticLiquid)state.getBlock()) : state.getBlock()) == this) && material != this.material && material != Material.LAVA && !this.isBlocked(worldIn, pos, state);
|
||||
return (this.material == Material.LAVA || !(state.getBlock() instanceof BlockLiquid) || (state.getBlock() instanceof BlockStaticLiquid ? ((BlockStaticLiquid)state.getBlock()).getFlowingBlock() : state.getBlock()) == this) && material != this.material && material != Material.LAVA && !this.isBlocked(worldIn, pos, state);
|
||||
}
|
||||
|
||||
public void onBlockAdded(AWorldServer worldIn, BlockPos pos, State state)
|
||||
|
@ -302,4 +313,14 @@ public class BlockDynamicLiquid extends BlockLiquid
|
|||
worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn, pos));
|
||||
}
|
||||
}
|
||||
|
||||
public void getAnimatedTextures(Map<String, Object> map) {
|
||||
map.put(BlockRegistry.getNameFromBlock(this.staticBlock) + "_flow", this.animation);
|
||||
}
|
||||
|
||||
public String getFallbackTexture() {
|
||||
if(this.cachedTexture == null)
|
||||
this.cachedTexture = BlockRegistry.getNameFromBlock(this.staticBlock) + "_still";
|
||||
return this.cachedTexture;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package common.block.liquid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import common.block.Block;
|
||||
import common.block.Material;
|
||||
import common.collect.Lists;
|
||||
import common.color.Colorizer;
|
||||
import common.entity.Entity;
|
||||
import common.init.Blocks;
|
||||
import common.init.FluidRegistry;
|
||||
import common.init.SoundEvent;
|
||||
import common.item.Item;
|
||||
import common.model.BlockLayer;
|
||||
|
@ -17,6 +19,7 @@ import common.util.BlockPos;
|
|||
import common.util.BoundingBox;
|
||||
import common.util.ExtMath;
|
||||
import common.util.Facing;
|
||||
import common.util.Pair;
|
||||
import common.util.Vec3;
|
||||
import common.vars.Vars;
|
||||
import common.world.IBlockAccess;
|
||||
|
@ -29,11 +32,15 @@ import common.world.AWorldServer;
|
|||
public abstract class BlockLiquid extends Block
|
||||
{
|
||||
public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 15);
|
||||
public static final List<Pair<BlockStaticLiquid, BlockDynamicLiquid>> LIQUIDS = Lists.newArrayList();
|
||||
|
||||
protected final boolean opaque;
|
||||
protected final int flowRate;
|
||||
protected final Object animation;
|
||||
|
||||
protected String cachedTexture;
|
||||
|
||||
public BlockLiquid(Material materialIn, boolean tick, boolean opaque, int rate)
|
||||
public BlockLiquid(Material materialIn, boolean tick, boolean opaque, int rate, Object animation)
|
||||
{
|
||||
super(materialIn);
|
||||
this.setDefaultState(this.getBaseState().withProperty(LEVEL, Integer.valueOf(0)));
|
||||
|
@ -42,6 +49,11 @@ public abstract class BlockLiquid extends Block
|
|||
this.setTickRandomly();
|
||||
this.opaque = opaque;
|
||||
this.flowRate = rate;
|
||||
this.animation = animation;
|
||||
}
|
||||
|
||||
public Object getAnimation() {
|
||||
return this.animation;
|
||||
}
|
||||
|
||||
public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
|
||||
|
@ -296,7 +308,7 @@ public abstract class BlockLiquid extends Block
|
|||
|
||||
public static double getFlowDirection(IBlockAccess worldIn, BlockPos pos, BlockLiquid block)
|
||||
{
|
||||
Vec3 vec3 = (block instanceof BlockStaticLiquid ? getFlowingBlock((BlockStaticLiquid)block) : block).getFlowVector(worldIn, pos);
|
||||
Vec3 vec3 = (block instanceof BlockStaticLiquid ? ((BlockStaticLiquid)block).getFlowingBlock() : block).getFlowVector(worldIn, pos);
|
||||
return vec3.xCoord == 0.0D && vec3.zCoord == 0.0D ? -1000.0D : ExtMath.atan2(vec3.zCoord, vec3.xCoord) - (Math.PI / 2D);
|
||||
}
|
||||
|
||||
|
@ -391,36 +403,4 @@ public abstract class BlockLiquid extends Block
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static BlockDynamicLiquid getFlowingBlock(BlockStaticLiquid block)
|
||||
{
|
||||
if (block.getMaterial() == Material.WATER)
|
||||
{
|
||||
return Blocks.flowing_water;
|
||||
}
|
||||
else if (block.getMaterial() == Material.LAVA)
|
||||
{
|
||||
return Blocks.flowing_lava;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FluidRegistry.getDynamicBlock(block);
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockStaticLiquid getStaticBlock(BlockDynamicLiquid block)
|
||||
{
|
||||
if (block.getMaterial() == Material.WATER)
|
||||
{
|
||||
return Blocks.water;
|
||||
}
|
||||
else if (block.getMaterial() == Material.LAVA)
|
||||
{
|
||||
return Blocks.lava;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FluidRegistry.getStaticBlock(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package common.block.liquid;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import common.block.Block;
|
||||
import common.block.Material;
|
||||
import common.init.BlockRegistry;
|
||||
import common.init.Blocks;
|
||||
import common.rng.Random;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.Pair;
|
||||
import common.vars.Vars;
|
||||
import common.world.State;
|
||||
import common.world.World;
|
||||
|
@ -13,15 +17,18 @@ import common.world.AWorldServer;
|
|||
|
||||
public class BlockStaticLiquid extends BlockLiquid
|
||||
{
|
||||
public BlockStaticLiquid(Material materialIn, boolean opaque, int rate)
|
||||
private final BlockDynamicLiquid dynamicBlock;
|
||||
|
||||
public BlockStaticLiquid(Material materialIn, boolean opaque, int rate, Object animation, BlockDynamicLiquid flowing)
|
||||
{
|
||||
super(materialIn, materialIn == Material.LAVA, opaque, rate);
|
||||
// this.setTickRandomly(false);
|
||||
//
|
||||
// if (materialIn == Material.lava)
|
||||
// {
|
||||
// this.setTickRandomly(true);
|
||||
// }
|
||||
super(materialIn, materialIn == Material.LAVA, opaque, rate, animation);
|
||||
this.dynamicBlock = flowing;
|
||||
flowing.setStaticBlock(this);
|
||||
LIQUIDS.add(new Pair<BlockStaticLiquid, BlockDynamicLiquid>(this, flowing));
|
||||
}
|
||||
|
||||
public BlockDynamicLiquid getFlowingBlock() {
|
||||
return this.dynamicBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,9 +44,8 @@ public class BlockStaticLiquid extends BlockLiquid
|
|||
|
||||
private void updateLiquid(World worldIn, BlockPos pos, State state)
|
||||
{
|
||||
BlockDynamicLiquid blockdynamicliquid = getFlowingBlock(this);
|
||||
worldIn.setState(pos, blockdynamicliquid.getState().withProperty(LEVEL, state.getValue(LEVEL)), 2);
|
||||
worldIn.scheduleUpdate(pos, blockdynamicliquid, this.tickRate(worldIn, pos));
|
||||
worldIn.setState(pos, this.dynamicBlock.getState().withProperty(LEVEL, state.getValue(LEVEL)), 2);
|
||||
worldIn.scheduleUpdate(pos, this.dynamicBlock, this.tickRate(worldIn, pos));
|
||||
}
|
||||
|
||||
public void updateTick(AWorldServer worldIn, BlockPos pos, State state, Random rand)
|
||||
|
@ -106,4 +112,14 @@ public class BlockStaticLiquid extends BlockLiquid
|
|||
{
|
||||
return worldIn.getState(pos).getBlock().getMaterial().getCanBurn();
|
||||
}
|
||||
|
||||
public void getAnimatedTextures(Map<String, Object> map) {
|
||||
map.put(BlockRegistry.getNameFromBlock(this) + "_still", this.animation);
|
||||
}
|
||||
|
||||
public String getFallbackTexture() {
|
||||
if(this.cachedTexture == null)
|
||||
this.cachedTexture = BlockRegistry.getNameFromBlock(this) + "_still";
|
||||
return this.cachedTexture;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1144,8 +1144,8 @@ public class BlockFire extends Block
|
|||
}
|
||||
|
||||
public void getAnimatedTextures(Map<String, Object> map) {
|
||||
map.put("blocks/fire_layer_0", TextureAnimation.FIRE1);
|
||||
map.put("blocks/fire_layer_1", TextureAnimation.FIRE2);
|
||||
map.put("fire_layer_0", TextureAnimation.FIRE1);
|
||||
map.put("fire_layer_1", TextureAnimation.FIRE2);
|
||||
}
|
||||
|
||||
public boolean canExtinguish() {
|
||||
|
|
|
@ -30,7 +30,7 @@ public class BlockTintedFire extends BlockFire {
|
|||
}
|
||||
|
||||
public void getAnimatedTextures(Map<String, Object> map) {
|
||||
map.put("blocks/flame_layer_0", TextureAnimation.FLAME1);
|
||||
map.put("blocks/flame_layer_1", TextureAnimation.FLAME2);
|
||||
map.put("flame_layer_0", TextureAnimation.FLAME1);
|
||||
map.put("flame_layer_1", TextureAnimation.FLAME2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -634,4 +634,8 @@ public class BlockChest extends BlockContainer implements Rotatable
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getFallbackTexture() {
|
||||
return "oak_planks";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,19 +4,12 @@ import common.block.Block;
|
|||
import common.block.BlockContainer;
|
||||
import common.block.Directional;
|
||||
import common.block.Material;
|
||||
import common.dispenser.BehaviorDefaultDispenseItem;
|
||||
import common.dispenser.IBehaviorDispenseItem;
|
||||
import common.dispenser.IBlockSource;
|
||||
import common.dispenser.IPosition;
|
||||
import common.dispenser.DispenserPos;
|
||||
import common.dispenser.DispenserSource;
|
||||
import common.entity.item.EntityItem;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.entity.types.EntityLiving;
|
||||
import common.init.DispenserRegistry;
|
||||
import common.inventory.Container;
|
||||
import common.inventory.InventoryHelper;
|
||||
import common.item.CheatTab;
|
||||
import common.item.Item;
|
||||
import common.item.ItemStack;
|
||||
import common.model.Model;
|
||||
import common.model.ModelProvider;
|
||||
|
@ -28,7 +21,7 @@ import common.tileentity.TileEntity;
|
|||
import common.tileentity.TileEntityDispenser;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.RegistryDefaulted;
|
||||
import common.util.Vec3;
|
||||
import common.world.State;
|
||||
import common.world.World;
|
||||
import common.world.AWorldServer;
|
||||
|
@ -36,8 +29,18 @@ import common.world.AWorldServer;
|
|||
public class BlockDispenser extends BlockContainer implements Directional
|
||||
{
|
||||
public static final PropertyBool TRIGGERED = PropertyBool.create("triggered");
|
||||
public static final RegistryDefaulted<Item, IBehaviorDispenseItem> dispenseBehaviorRegistry = new RegistryDefaulted(new BehaviorDefaultDispenseItem());
|
||||
|
||||
protected Random rand = new Random();
|
||||
|
||||
public static void dispense(World world, double speed, Facing facing, Vec3 position, ItemStack stack)
|
||||
{
|
||||
EntityItem entity = new EntityItem(world, position.xCoord, position.yCoord - (facing.getAxis() == Facing.Axis.Y ? 0.125 : 0.15625), position.zCoord, stack);
|
||||
double velo = world.rand.doublev() * 0.1 + 0.2;
|
||||
entity.motionX = (double)facing.getFrontOffsetX() * velo + world.rand.gaussian() * 0.0075 * speed;
|
||||
entity.motionY = 0.2 + world.rand.gaussian() * 0.0075 * speed;
|
||||
entity.motionZ = (double)facing.getFrontOffsetZ() * velo + world.rand.gaussian() * 0.0075 * speed;
|
||||
world.spawnEntityInWorld(entity);
|
||||
}
|
||||
|
||||
public BlockDispenser()
|
||||
{
|
||||
|
@ -125,10 +128,9 @@ public class BlockDispenser extends BlockContainer implements Directional
|
|||
|
||||
protected void dispense(World worldIn, BlockPos pos)
|
||||
{
|
||||
DispenserSource blocksourceimpl = new DispenserSource(worldIn, pos);
|
||||
TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();
|
||||
TileEntity te = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentitydispenser != null)
|
||||
if (te instanceof TileEntityDispenser tileentitydispenser)
|
||||
{
|
||||
int i = tileentitydispenser.getDispenseSlot();
|
||||
|
||||
|
@ -139,20 +141,23 @@ public class BlockDispenser extends BlockContainer implements Directional
|
|||
else
|
||||
{
|
||||
ItemStack itemstack = tileentitydispenser.getStackInSlot(i);
|
||||
IBehaviorDispenseItem ibehaviordispenseitem = this.getBehavior(itemstack);
|
||||
|
||||
if (ibehaviordispenseitem != IBehaviorDispenseItem.itemDispenseBehaviorProvider)
|
||||
{
|
||||
ItemStack itemstack1 = ibehaviordispenseitem.dispense(blocksourceimpl, itemstack);
|
||||
tileentitydispenser.setInventorySlotContents(i, itemstack1.size <= 0 ? null : itemstack1);
|
||||
if(itemstack != null) {
|
||||
ItemStack itemstack1 = this.dispenseStack(itemstack, worldIn, pos);
|
||||
tileentitydispenser.setInventorySlotContents(i, itemstack1.size <= 0 ? null : itemstack1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected IBehaviorDispenseItem getBehavior(ItemStack stack)
|
||||
protected ItemStack dispenseStack(ItemStack stack, World world, BlockPos pos)
|
||||
{
|
||||
return (IBehaviorDispenseItem)DispenserRegistry.REGISTRY.getObject(stack == null ? null : stack.getItem());
|
||||
Facing facing = world.getState(pos).getValue(FACING);
|
||||
ItemStack nstack = stack.getItem().dispenseStack(world, world.getTileEntity(pos), getDispensePosition(pos, facing), pos, facing, stack);
|
||||
int id = stack.getItem().getDispenseSoundId();
|
||||
if(id != 0)
|
||||
world.playAuxSFX(id, pos, 0);
|
||||
world.playAuxSFX(2000, pos, facing.getFrontOffsetX() + 1 + (facing.getFrontOffsetZ() + 1) * 3);
|
||||
return nstack;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -230,21 +235,14 @@ public class BlockDispenser extends BlockContainer implements Directional
|
|||
super.onBlockRemoved(worldIn, pos, state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position where the dispenser at the given Coordinates should dispense to.
|
||||
*/
|
||||
public static IPosition getDispensePosition(IBlockSource coords)
|
||||
public static Vec3 getDispensePosition(BlockPos pos, Facing facing)
|
||||
{
|
||||
Facing enumfacing = getFacing(coords.getBlockMetadata());
|
||||
double d0 = coords.getX() + 0.7D * (double)enumfacing.getFrontOffsetX();
|
||||
double d1 = coords.getY() + 0.7D * (double)enumfacing.getFrontOffsetY();
|
||||
double d2 = coords.getZ() + 0.7D * (double)enumfacing.getFrontOffsetZ();
|
||||
return new DispenserPos(d0, d1, d2);
|
||||
double d0 = pos.getX() + 0.5 + 0.7D * (double)facing.getFrontOffsetX();
|
||||
double d1 = pos.getY() + 0.5 + 0.7D * (double)facing.getFrontOffsetY();
|
||||
double d2 = pos.getZ() + 0.5 + 0.7D * (double)facing.getFrontOffsetZ();
|
||||
return new Vec3(d0, d1, d2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the facing of a dispenser with the given metadata
|
||||
*/
|
||||
public static Facing getFacing(int meta)
|
||||
{
|
||||
return Facing.getFront(meta & 7);
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package common.block.tech;
|
||||
|
||||
import common.dispenser.BehaviorDefaultDispenseItem;
|
||||
import common.dispenser.DispenserSource;
|
||||
import common.dispenser.IBehaviorDispenseItem;
|
||||
import common.inventory.IInventory;
|
||||
import common.item.ItemStack;
|
||||
import common.tileentity.TileEntity;
|
||||
|
@ -15,11 +12,13 @@ import common.world.World;
|
|||
|
||||
public class BlockDropper extends BlockDispenser
|
||||
{
|
||||
private final IBehaviorDispenseItem dropBehavior = new BehaviorDefaultDispenseItem();
|
||||
|
||||
protected IBehaviorDispenseItem getBehavior(ItemStack stack)
|
||||
protected ItemStack dispenseStack(ItemStack stack, World world, BlockPos pos)
|
||||
{
|
||||
return this.dropBehavior;
|
||||
Facing facing = world.getState(pos).getValue(FACING);
|
||||
dispense(world, 6.0, facing, getDispensePosition(pos, facing), stack.splitStack(1));
|
||||
world.playAuxSFX(1000, pos, 0);
|
||||
world.playAuxSFX(2000, pos, facing.getFrontOffsetX() + 1 + (facing.getFrontOffsetZ() + 1) * 3);
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,10 +31,9 @@ public class BlockDropper extends BlockDispenser
|
|||
|
||||
protected void dispense(World worldIn, BlockPos pos)
|
||||
{
|
||||
DispenserSource blocksourceimpl = new DispenserSource(worldIn, pos);
|
||||
TileEntityDispenser tileentitydispenser = (TileEntityDispenser)blocksourceimpl.getBlockTileEntity();
|
||||
TileEntity te = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentitydispenser != null)
|
||||
if (te instanceof TileEntityDispenser tileentitydispenser)
|
||||
{
|
||||
int i = tileentitydispenser.getDispenseSlot();
|
||||
|
||||
|
@ -56,7 +54,7 @@ public class BlockDropper extends BlockDispenser
|
|||
|
||||
if (iinventory == null)
|
||||
{
|
||||
itemstack1 = this.dropBehavior.dispense(blocksourceimpl, itemstack);
|
||||
itemstack1 = this.dispenseStack(itemstack, worldIn, pos);
|
||||
|
||||
if (itemstack1 != null && itemstack1.size <= 0)
|
||||
{
|
||||
|
|
|
@ -21,6 +21,6 @@ public class BlockTianReactor extends BlockMachine {
|
|||
}
|
||||
|
||||
public void getAnimatedTextures(Map<String, Object> map) {
|
||||
map.put("blocks/tian_reactor_front", 5);
|
||||
map.put("tian_reactor_front", 5);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,4 +144,8 @@ public class BlockBanner extends BlockContainer implements Rotatable
|
|||
public Transforms getTransform() {
|
||||
return Transforms.BANNER;
|
||||
}
|
||||
|
||||
public String getFallbackTexture() {
|
||||
return "oak_planks";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,4 +131,8 @@ public class BlockSign extends BlockContainer
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getFallbackTexture() {
|
||||
return "oak_planks";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
package common.dispenser;
|
||||
|
||||
import common.block.tech.BlockDispenser;
|
||||
import common.entity.item.EntityItem;
|
||||
import common.item.ItemStack;
|
||||
import common.util.Facing;
|
||||
import common.world.World;
|
||||
|
||||
public class BehaviorDefaultDispenseItem implements IBehaviorDispenseItem
|
||||
{
|
||||
/**
|
||||
* Dispenses the specified ItemStack from a dispenser.
|
||||
*/
|
||||
public final ItemStack dispense(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
ItemStack itemstack = this.dispenseStack(source, stack);
|
||||
this.playDispenseSound(source);
|
||||
this.spawnDispenseParticles(source, BlockDispenser.getFacing(source.getBlockMetadata()));
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispense the specified stack, play the dispense sound and spawn particles.
|
||||
*/
|
||||
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
Facing enumfacing = BlockDispenser.getFacing(source.getBlockMetadata());
|
||||
IPosition iposition = BlockDispenser.getDispensePosition(source);
|
||||
ItemStack itemstack = stack.splitStack(1);
|
||||
doDispense(source.getWorld(), itemstack, 6, enumfacing, iposition);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static void doDispense(World worldIn, ItemStack stack, int speed, Facing facing, IPosition position)
|
||||
{
|
||||
double d0 = position.getX();
|
||||
double d1 = position.getY();
|
||||
double d2 = position.getZ();
|
||||
|
||||
if (facing.getAxis() == Facing.Axis.Y)
|
||||
{
|
||||
d1 = d1 - 0.125D;
|
||||
}
|
||||
else
|
||||
{
|
||||
d1 = d1 - 0.15625D;
|
||||
}
|
||||
|
||||
EntityItem entityitem = new EntityItem(worldIn, d0, d1, d2, stack);
|
||||
double d3 = worldIn.rand.doublev() * 0.1D + 0.2D;
|
||||
entityitem.motionX = (double)facing.getFrontOffsetX() * d3;
|
||||
entityitem.motionY = 0.20000000298023224D;
|
||||
entityitem.motionZ = (double)facing.getFrontOffsetZ() * d3;
|
||||
entityitem.motionX += worldIn.rand.gaussian() * 0.007499999832361937D * (double)speed;
|
||||
entityitem.motionY += worldIn.rand.gaussian() * 0.007499999832361937D * (double)speed;
|
||||
entityitem.motionZ += worldIn.rand.gaussian() * 0.007499999832361937D * (double)speed;
|
||||
worldIn.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Play the dispense sound from the specified block.
|
||||
*/
|
||||
protected void playDispenseSound(IBlockSource source)
|
||||
{
|
||||
source.getWorld().playAuxSFX(1000, source.getBlockPos(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Order clients to display dispense particles from the specified block and facing.
|
||||
*/
|
||||
protected void spawnDispenseParticles(IBlockSource source, Facing facingIn)
|
||||
{
|
||||
source.getWorld().playAuxSFX(2000, source.getBlockPos(), this.getOffsetId(facingIn));
|
||||
}
|
||||
|
||||
private int getOffsetId(Facing facingIn)
|
||||
{
|
||||
return facingIn.getFrontOffsetX() + 1 + (facingIn.getFrontOffsetZ() + 1) * 3;
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package common.dispenser;
|
||||
|
||||
import common.block.tech.BlockDispenser;
|
||||
import common.entity.Entity;
|
||||
import common.entity.types.IProjectile;
|
||||
import common.item.ItemStack;
|
||||
import common.util.Facing;
|
||||
import common.world.World;
|
||||
|
||||
public abstract class BehaviorProjectileDispense extends BehaviorDefaultDispenseItem
|
||||
{
|
||||
/**
|
||||
* Dispense the specified stack, play the dispense sound and spawn particles.
|
||||
*/
|
||||
public ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
World world = source.getWorld();
|
||||
IPosition iposition = BlockDispenser.getDispensePosition(source);
|
||||
Facing enumfacing = BlockDispenser.getFacing(source.getBlockMetadata());
|
||||
IProjectile iprojectile = this.getProjectileEntity(world, iposition, stack);
|
||||
iprojectile.setThrowableHeading((double)enumfacing.getFrontOffsetX(), (double)((float)enumfacing.getFrontOffsetY() + 0.1F), (double)enumfacing.getFrontOffsetZ(), this.getVelocity(), this.getInaccuracy());
|
||||
world.spawnEntityInWorld((Entity)iprojectile);
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Play the dispense sound from the specified block.
|
||||
*/
|
||||
protected void playDispenseSound(IBlockSource source)
|
||||
{
|
||||
source.getWorld().playAuxSFX(1002, source.getBlockPos(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the projectile entity spawned by this dispense behavior.
|
||||
*/
|
||||
protected abstract IProjectile getProjectileEntity(World worldIn, IPosition position, ItemStack item);
|
||||
|
||||
protected float getInaccuracy()
|
||||
{
|
||||
return 6.0F;
|
||||
}
|
||||
|
||||
protected float getVelocity()
|
||||
{
|
||||
return 1.1F;
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package common.dispenser;
|
||||
|
||||
public record DispenserPos(double getX, double getY, double getZ) implements IPosition {
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package common.dispenser;
|
||||
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.world.State;
|
||||
import common.world.World;
|
||||
|
||||
public record DispenserSource(World getWorld, BlockPos getBlockPos) implements IBlockSource {
|
||||
public double getX() {
|
||||
return (double)this.getBlockPos.getX() + 0.5D;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return (double)this.getBlockPos.getY() + 0.5D;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return (double)this.getBlockPos.getZ() + 0.5D;
|
||||
}
|
||||
|
||||
public int getBlockMetadata() {
|
||||
State state = this.getWorld.getState(this.getBlockPos);
|
||||
return state.getBlock().getMetaFromState(state);
|
||||
}
|
||||
|
||||
public <T extends TileEntity> T getBlockTileEntity() {
|
||||
return (T)this.getWorld.getTileEntity(this.getBlockPos);
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package common.dispenser;
|
||||
|
||||
import common.item.ItemStack;
|
||||
|
||||
public interface IBehaviorDispenseItem
|
||||
{
|
||||
IBehaviorDispenseItem itemDispenseBehaviorProvider = new IBehaviorDispenseItem()
|
||||
{
|
||||
public ItemStack dispense(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispenses the specified ItemStack from a dispenser.
|
||||
*/
|
||||
ItemStack dispense(IBlockSource source, ItemStack stack);
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package common.dispenser;
|
||||
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.world.World;
|
||||
|
||||
public interface IBlockSource extends IPosition
|
||||
{
|
||||
double getX();
|
||||
|
||||
double getY();
|
||||
|
||||
double getZ();
|
||||
|
||||
World getWorld();
|
||||
|
||||
BlockPos getBlockPos();
|
||||
|
||||
int getBlockMetadata();
|
||||
|
||||
<T extends TileEntity> T getBlockTileEntity();
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package common.dispenser;
|
||||
|
||||
public interface IPosition
|
||||
{
|
||||
double getX();
|
||||
|
||||
double getY();
|
||||
|
||||
double getZ();
|
||||
}
|
|
@ -58,6 +58,7 @@ import common.block.foliage.BlockVine;
|
|||
import common.block.foliage.BlockWart;
|
||||
import common.block.foliage.LeavesType;
|
||||
import common.block.liquid.BlockDynamicLiquid;
|
||||
import common.block.liquid.BlockLiquid;
|
||||
import common.block.liquid.BlockStaticLiquid;
|
||||
import common.block.natural.BlockBedrock;
|
||||
import common.block.natural.BlockBlackenedDirt;
|
||||
|
@ -127,7 +128,6 @@ import common.block.tile.BlockBannerStanding;
|
|||
import common.block.tile.BlockStandingSign;
|
||||
import common.block.tile.BlockWallSign;
|
||||
import common.color.DyeColor;
|
||||
import common.init.FluidRegistry.LiquidType;
|
||||
import common.item.CheatTab;
|
||||
import common.log.Log;
|
||||
import common.model.TextureAnimation;
|
||||
|
@ -151,6 +151,10 @@ public abstract class BlockRegistry {
|
|||
return REGISTRY.getNameForObject(block);
|
||||
}
|
||||
|
||||
public static String getNameFromFluid(BlockLiquid block) {
|
||||
return REGISTRY.getNameForObject(block instanceof BlockDynamicLiquid dy ? dy.getStaticBlock() : block);
|
||||
}
|
||||
|
||||
public static int getStateId(State state) {
|
||||
Block block = state.getBlock();
|
||||
return getIdFromBlock(block) + (block.getMetaFromState(state) << 12);
|
||||
|
@ -225,15 +229,14 @@ public abstract class BlockRegistry {
|
|||
|
||||
private static void registerFluid(String name, String display, boolean infinite, LiquidType type, boolean opaque, int light, int rate,
|
||||
float radiation, Object still, Object flowing) {
|
||||
BlockDynamicLiquid dy = (BlockDynamicLiquid)(new BlockDynamicLiquid(type.material, infinite, opaque, rate)).setHardness(100.0F)
|
||||
BlockDynamicLiquid dy = (BlockDynamicLiquid)(new BlockDynamicLiquid(type.material, infinite, opaque, rate, flowing)).setHardness(100.0F)
|
||||
.setLightOpacity(opaque ? 0 : 3).setLightLevel((float)light / 15.0f).setDisplay(display)
|
||||
.setRadiation(radiation);
|
||||
BlockStaticLiquid st = (BlockStaticLiquid)(new BlockStaticLiquid(type.material, opaque, rate, still, dy)).setHardness(100.0F)
|
||||
.setLightOpacity(opaque ? 0 : 3).setLightLevel((float)light / 15.0f).setDisplay(display)
|
||||
.setRadiation(radiation);
|
||||
registerBlock("flowing_" + name, dy);
|
||||
BlockStaticLiquid st = (BlockStaticLiquid)(new BlockStaticLiquid(type.material, opaque, rate)).setHardness(100.0F)
|
||||
.setLightOpacity(opaque ? 0 : 3).setLightLevel((float)light / 15.0f).setDisplay(display)
|
||||
.setRadiation(radiation);
|
||||
registerBlock(name, st);
|
||||
FluidRegistry.registerFluid(st, dy, still, flowing);
|
||||
}
|
||||
|
||||
private static void registerBlocks() {
|
||||
|
|
|
@ -1,409 +0,0 @@
|
|||
package common.init;
|
||||
|
||||
import common.block.Block;
|
||||
import common.block.Material;
|
||||
import common.block.liquid.BlockDynamicLiquid;
|
||||
import common.block.liquid.BlockLiquid;
|
||||
import common.block.tech.BlockDispenser;
|
||||
import common.block.tech.BlockTNT;
|
||||
import common.dispenser.BehaviorDefaultDispenseItem;
|
||||
import common.dispenser.BehaviorProjectileDispense;
|
||||
import common.dispenser.IBehaviorDispenseItem;
|
||||
import common.dispenser.IBlockSource;
|
||||
import common.dispenser.IPosition;
|
||||
import common.entity.Entity;
|
||||
import common.entity.item.EntityBoat;
|
||||
import common.entity.item.EntityFireworks;
|
||||
import common.entity.item.EntityTnt;
|
||||
import common.entity.item.EntityXpBottle;
|
||||
import common.entity.projectile.EntityArrow;
|
||||
import common.entity.projectile.EntityDie;
|
||||
import common.entity.projectile.EntityDynamite;
|
||||
import common.entity.projectile.EntityEgg;
|
||||
import common.entity.projectile.EntityFireCharge;
|
||||
import common.entity.projectile.EntityPotion;
|
||||
import common.entity.projectile.EntitySnowball;
|
||||
import common.entity.types.EntityLiving;
|
||||
import common.entity.types.IProjectile;
|
||||
import common.item.Item;
|
||||
import common.item.ItemBucket;
|
||||
import common.item.ItemDie;
|
||||
import common.item.ItemDye;
|
||||
import common.item.ItemMonsterPlacer;
|
||||
import common.item.ItemPotion;
|
||||
import common.item.ItemStack;
|
||||
import common.rng.Random;
|
||||
import common.tileentity.TileEntityDispenser;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.RegistryDefaulted;
|
||||
import common.world.State;
|
||||
import common.world.World;
|
||||
|
||||
public abstract class DispenserRegistry {
|
||||
public static final RegistryDefaulted<Item, IBehaviorDispenseItem> REGISTRY = new RegistryDefaulted<Item, IBehaviorDispenseItem>(new BehaviorDefaultDispenseItem());
|
||||
|
||||
static void register() {
|
||||
REGISTRY.putObject(Items.arrow, new BehaviorProjectileDispense()
|
||||
{
|
||||
protected IProjectile getProjectileEntity(World worldIn, IPosition position, ItemStack item)
|
||||
{
|
||||
EntityArrow entityarrow = new EntityArrow(worldIn, position.getX(), position.getY(), position.getZ());
|
||||
entityarrow.canBePickedUp = 1;
|
||||
return entityarrow;
|
||||
}
|
||||
});
|
||||
REGISTRY.putObject(Items.egg, new BehaviorProjectileDispense()
|
||||
{
|
||||
protected IProjectile getProjectileEntity(World worldIn, IPosition position, ItemStack item)
|
||||
{
|
||||
return new EntityEgg(worldIn, position.getX(), position.getY(), position.getZ());
|
||||
}
|
||||
});
|
||||
for(final ItemDie die : ItemDie.getDieItems()) {
|
||||
REGISTRY.putObject(die, new BehaviorProjectileDispense()
|
||||
{
|
||||
protected IProjectile getProjectileEntity(World worldIn, IPosition position, ItemStack item)
|
||||
{
|
||||
return new EntityDie(worldIn, position.getX(), position.getY(), position.getZ(), die.getSides());
|
||||
}
|
||||
protected float getInaccuracy()
|
||||
{
|
||||
return super.getInaccuracy() * 5.0F;
|
||||
}
|
||||
protected float getVelocity()
|
||||
{
|
||||
return super.getVelocity() * 0.25F;
|
||||
}
|
||||
});
|
||||
}
|
||||
for(int z = 0; z < 8; z++) {
|
||||
final int power = z;
|
||||
REGISTRY.putObject(ItemRegistry.getRegisteredItem("dynamite" + (power == 0 ? "" : "_" + power)), new BehaviorProjectileDispense()
|
||||
{
|
||||
protected IProjectile getProjectileEntity(World worldIn, IPosition position, ItemStack item)
|
||||
{
|
||||
return new EntityDynamite(worldIn, position.getX(), position.getY(), position.getZ(), power);
|
||||
}
|
||||
});
|
||||
}
|
||||
REGISTRY.putObject(Items.snowball, new BehaviorProjectileDispense()
|
||||
{
|
||||
protected IProjectile getProjectileEntity(World worldIn, IPosition position, ItemStack item)
|
||||
{
|
||||
return new EntitySnowball(worldIn, position.getX(), position.getY(), position.getZ());
|
||||
}
|
||||
});
|
||||
REGISTRY.putObject(Items.experience_bottle, new BehaviorProjectileDispense()
|
||||
{
|
||||
protected IProjectile getProjectileEntity(World worldIn, IPosition position, ItemStack item)
|
||||
{
|
||||
return new EntityXpBottle(worldIn, position.getX(), position.getY(), position.getZ());
|
||||
}
|
||||
protected float getInaccuracy()
|
||||
{
|
||||
return super.getInaccuracy() * 0.5F;
|
||||
}
|
||||
protected float getVelocity()
|
||||
{
|
||||
return super.getVelocity() * 1.25F;
|
||||
}
|
||||
});
|
||||
for(ItemPotion potion : ItemPotion.getPotions()) {
|
||||
if(potion.isSplashPotion())
|
||||
REGISTRY.putObject(potion, new BehaviorProjectileDispense()
|
||||
{
|
||||
protected IProjectile getProjectileEntity(World worldIn, IPosition position, ItemStack item)
|
||||
{
|
||||
return new EntityPotion(worldIn, position.getX(), position.getY(), position.getZ(), item.copy());
|
||||
}
|
||||
protected float getInaccuracy()
|
||||
{
|
||||
return super.getInaccuracy() * 0.5F;
|
||||
}
|
||||
protected float getVelocity()
|
||||
{
|
||||
return super.getVelocity() * 1.25F;
|
||||
}
|
||||
});
|
||||
}
|
||||
IBehaviorDispenseItem disp = new BehaviorDefaultDispenseItem()
|
||||
{
|
||||
public ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
Facing enumfacing = BlockDispenser.getFacing(source.getBlockMetadata());
|
||||
double d0 = source.getX() + (double)enumfacing.getFrontOffsetX();
|
||||
double d1 = (double)((float)source.getBlockPos().getY() + 0.2F);
|
||||
double d2 = source.getZ() + (double)enumfacing.getFrontOffsetZ();
|
||||
Entity entity = ItemMonsterPlacer.spawnCreature(source.getWorld(), ((ItemMonsterPlacer)stack.getItem()).getSpawnedId(),
|
||||
d0, d1, d2, false);
|
||||
|
||||
if (entity instanceof EntityLiving && stack.hasDisplayName())
|
||||
{
|
||||
((EntityLiving)entity).setCustomNameTag(stack.getDisplayName());
|
||||
}
|
||||
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
};
|
||||
for(EntityInfo egg : EntityRegistry.SPAWN_EGGS.values()) {
|
||||
REGISTRY.putObject(ItemRegistry.getRegisteredItem(egg.id().toLowerCase() + "_spawner"),
|
||||
disp);
|
||||
}
|
||||
REGISTRY.putObject(Items.fireworks, new BehaviorDefaultDispenseItem()
|
||||
{
|
||||
public ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
Facing enumfacing = BlockDispenser.getFacing(source.getBlockMetadata());
|
||||
double d0 = source.getX() + (double)enumfacing.getFrontOffsetX();
|
||||
double d1 = (double)((float)source.getBlockPos().getY() + 0.2F);
|
||||
double d2 = source.getZ() + (double)enumfacing.getFrontOffsetZ();
|
||||
EntityFireworks entityfireworkrocket = new EntityFireworks(source.getWorld(), d0, d1, d2, stack);
|
||||
source.getWorld().spawnEntityInWorld(entityfireworkrocket);
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
protected void playDispenseSound(IBlockSource source)
|
||||
{
|
||||
source.getWorld().playAuxSFX(1002, source.getBlockPos(), 0);
|
||||
}
|
||||
});
|
||||
REGISTRY.putObject(Items.fire_charge, new BehaviorDefaultDispenseItem()
|
||||
{
|
||||
public ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
Facing enumfacing = BlockDispenser.getFacing(source.getBlockMetadata());
|
||||
IPosition iposition = BlockDispenser.getDispensePosition(source);
|
||||
double d0 = iposition.getX() + (double)((float)enumfacing.getFrontOffsetX() * 0.3F);
|
||||
double d1 = iposition.getY() + (double)((float)enumfacing.getFrontOffsetY() * 0.3F);
|
||||
double d2 = iposition.getZ() + (double)((float)enumfacing.getFrontOffsetZ() * 0.3F);
|
||||
World world = source.getWorld();
|
||||
Random random = world.rand;
|
||||
double d3 = random.gaussian() * 0.05D + (double)enumfacing.getFrontOffsetX();
|
||||
double d4 = random.gaussian() * 0.05D + (double)enumfacing.getFrontOffsetY();
|
||||
double d5 = random.gaussian() * 0.05D + (double)enumfacing.getFrontOffsetZ();
|
||||
world.spawnEntityInWorld(new EntityFireCharge(world, d0, d1, d2, d3, d4, d5));
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
protected void playDispenseSound(IBlockSource source)
|
||||
{
|
||||
source.getWorld().playAuxSFX(1009, source.getBlockPos(), 0);
|
||||
}
|
||||
});
|
||||
REGISTRY.putObject(Items.boat, new BehaviorDefaultDispenseItem()
|
||||
{
|
||||
private final BehaviorDefaultDispenseItem field_150842_b = new BehaviorDefaultDispenseItem();
|
||||
public ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
Facing enumfacing = BlockDispenser.getFacing(source.getBlockMetadata());
|
||||
World world = source.getWorld();
|
||||
double d0 = source.getX() + (double)((float)enumfacing.getFrontOffsetX() * 1.125F);
|
||||
double d1 = source.getY() + (double)((float)enumfacing.getFrontOffsetY() * 1.125F);
|
||||
double d2 = source.getZ() + (double)((float)enumfacing.getFrontOffsetZ() * 1.125F);
|
||||
BlockPos blockpos = source.getBlockPos().offset(enumfacing);
|
||||
Block block = world.getState(blockpos).getBlock();
|
||||
double d3;
|
||||
|
||||
if (block.getMaterial().isColdLiquid())
|
||||
{
|
||||
d3 = 1.0D;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (block != Blocks.air || !world.getState(blockpos.down()).getBlock().getMaterial().isColdLiquid())
|
||||
{
|
||||
return this.field_150842_b.dispense(source, stack);
|
||||
}
|
||||
|
||||
d3 = 0.0D;
|
||||
}
|
||||
|
||||
EntityBoat entityboat = new EntityBoat(world, d0, d1 + d3, d2);
|
||||
world.spawnEntityInWorld(entityboat);
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
protected void playDispenseSound(IBlockSource source)
|
||||
{
|
||||
source.getWorld().playAuxSFX(1000, source.getBlockPos(), 0);
|
||||
}
|
||||
});
|
||||
IBehaviorDispenseItem ibehaviordispenseitem = new BehaviorDefaultDispenseItem()
|
||||
{
|
||||
private final BehaviorDefaultDispenseItem field_150841_b = new BehaviorDefaultDispenseItem();
|
||||
public ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
ItemBucket itembucket = (ItemBucket)stack.getItem();
|
||||
BlockPos blockpos = source.getBlockPos().offset(BlockDispenser.getFacing(source.getBlockMetadata()));
|
||||
|
||||
if (itembucket.tryPlaceContainedLiquid(source.getWorld(), blockpos))
|
||||
{
|
||||
stack.setItem(Items.bucket);
|
||||
stack.size = 1;
|
||||
return stack;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.field_150841_b.dispense(source, stack);
|
||||
}
|
||||
}
|
||||
};
|
||||
// REGISTRY.putObject(Items.lava_bucket, ibehaviordispenseitem);
|
||||
// REGISTRY.putObject(Items.water_bucket, ibehaviordispenseitem);
|
||||
// REGISTRY.putObject(Items.fluid_bucket, ibehaviordispenseitem);
|
||||
for(int z = 0; z < FluidRegistry.getNumFluids(); z++) {
|
||||
REGISTRY.putObject(ItemRegistry.getRegisteredItem(BlockRegistry.getNameFromBlock(FluidRegistry.getStaticBlock(z)) +
|
||||
"_bucket"), ibehaviordispenseitem);
|
||||
}
|
||||
REGISTRY.putObject(Items.bucket, new BehaviorDefaultDispenseItem()
|
||||
{
|
||||
private final BehaviorDefaultDispenseItem field_150840_b = new BehaviorDefaultDispenseItem();
|
||||
public ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
World world = source.getWorld();
|
||||
BlockPos blockpos = source.getBlockPos().offset(BlockDispenser.getFacing(source.getBlockMetadata()));
|
||||
State iblockstate = world.getState(blockpos);
|
||||
Block block = iblockstate.getBlock();
|
||||
Material material = block.getMaterial();
|
||||
Item item;
|
||||
// int meta = 0;
|
||||
|
||||
// if (Material.water.equals(material) && block instanceof BlockLiquid && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
|
||||
// {
|
||||
// item = Items.water_bucket;
|
||||
// }
|
||||
// else if (Material.lava.equals(material) && block instanceof BlockLiquid && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
|
||||
// {
|
||||
// item = Items.lava_bucket;
|
||||
// }
|
||||
// else
|
||||
if (material.isLiquid() && block instanceof BlockLiquid && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
|
||||
{
|
||||
item = ItemRegistry.getRegisteredItem(BlockRegistry.getNameFromBlock(block instanceof BlockDynamicLiquid
|
||||
? FluidRegistry.getStaticBlock((BlockDynamicLiquid)block) : block) +
|
||||
"_bucket"); // Items.fluid_bucket;
|
||||
// meta = FluidRegistry.getFluidMeta((BlockLiquid)iblockstate.getBlock());
|
||||
}
|
||||
else
|
||||
{
|
||||
// if (!Material.lava.equals(material) || !(block instanceof BlockLiquid) || ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() != 0)
|
||||
// {
|
||||
return super.dispenseStack(source, stack);
|
||||
// }
|
||||
//
|
||||
// item = Items.lava_bucket;
|
||||
}
|
||||
|
||||
world.setBlockToAir(blockpos);
|
||||
|
||||
if (--stack.size == 0)
|
||||
{
|
||||
stack.setItem(item);
|
||||
stack.size = 1;
|
||||
}
|
||||
else if (((TileEntityDispenser)source.getBlockTileEntity()).addItemStack(new ItemStack(item)) < 0)
|
||||
{
|
||||
this.field_150840_b.dispense(source, new ItemStack(item));
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
});
|
||||
REGISTRY.putObject(Items.flint_and_steel, new BehaviorDefaultDispenseItem()
|
||||
{
|
||||
private boolean success = true;
|
||||
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
World world = source.getWorld();
|
||||
BlockPos blockpos = source.getBlockPos().offset(BlockDispenser.getFacing(source.getBlockMetadata()));
|
||||
|
||||
if (world.isAirBlock(blockpos))
|
||||
{
|
||||
world.setState(blockpos, Blocks.fire.getState());
|
||||
|
||||
if (stack.attemptDamageItem(1, world.rand))
|
||||
{
|
||||
stack.size = 0;
|
||||
}
|
||||
this.success = true;
|
||||
}
|
||||
else if (world.getState(blockpos).getBlock() == Blocks.tnt)
|
||||
{
|
||||
Blocks.tnt.onBlockDestroyedByPlayer(world, blockpos, Blocks.tnt.getState().withProperty(BlockTNT.EXPLODE, Boolean.valueOf(true)));
|
||||
world.setBlockToAir(blockpos);
|
||||
this.success = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.success = false;
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
protected void playDispenseSound(IBlockSource source)
|
||||
{
|
||||
if (this.success)
|
||||
{
|
||||
source.getWorld().playAuxSFX(1000, source.getBlockPos(), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
source.getWorld().playAuxSFX(1001, source.getBlockPos(), 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
REGISTRY.putObject(Items.bonemeal, new BehaviorDefaultDispenseItem()
|
||||
{
|
||||
private boolean success = true;
|
||||
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
World world = source.getWorld();
|
||||
BlockPos blockpos = source.getBlockPos().offset(BlockDispenser.getFacing(source.getBlockMetadata()));
|
||||
|
||||
if (ItemDye.applyBonemeal(stack, world, blockpos))
|
||||
{
|
||||
if (!world.client)
|
||||
{
|
||||
world.playAuxSFX(2005, blockpos, 0);
|
||||
}
|
||||
this.success = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.success = false;
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
protected void playDispenseSound(IBlockSource source)
|
||||
{
|
||||
if (this.success)
|
||||
{
|
||||
source.getWorld().playAuxSFX(1000, source.getBlockPos(), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
source.getWorld().playAuxSFX(1001, source.getBlockPos(), 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
for(int z = 0; z < 8; z++) {
|
||||
final int power = z;
|
||||
REGISTRY.putObject(ItemRegistry.getRegisteredItem("tnt" + (power == 0 ? "" : "_" + power)), new BehaviorDefaultDispenseItem()
|
||||
{
|
||||
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
World world = source.getWorld();
|
||||
BlockPos blockpos = source.getBlockPos().offset(BlockDispenser.getFacing(source.getBlockMetadata()));
|
||||
EntityTnt entitytntprimed = new EntityTnt(world, (double)blockpos.getX() + 0.5D, (double)blockpos.getY(), (double)blockpos.getZ() + 0.5D, (EntityLiving)null, power);
|
||||
world.spawnEntityInWorld(entitytntprimed);
|
||||
world.playSoundAtEntity(entitytntprimed, SoundEvent.FUSE, 1.0F);
|
||||
--stack.size;
|
||||
return stack;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
package common.init;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import common.block.Block;
|
||||
import common.block.Material;
|
||||
import common.block.liquid.BlockDynamicLiquid;
|
||||
import common.block.liquid.BlockLiquid;
|
||||
import common.block.liquid.BlockStaticLiquid;
|
||||
import common.collect.Lists;
|
||||
import common.collect.Maps;
|
||||
|
||||
public abstract class FluidRegistry {
|
||||
public static enum LiquidType {
|
||||
COLD(Material.COLD), HOT(Material.HOT), WATER(Material.WATER), LAVA(Material.LAVA);
|
||||
|
||||
public final Material material;
|
||||
|
||||
private LiquidType(Material material) {
|
||||
this.material = material;
|
||||
}
|
||||
}
|
||||
|
||||
static class FluidInfo {
|
||||
private final int id;
|
||||
private final BlockStaticLiquid stBlock;
|
||||
private final BlockDynamicLiquid dyBlock;
|
||||
private final Object stAnim;
|
||||
private final Object dyAnim;
|
||||
|
||||
private FluidInfo(int id, BlockStaticLiquid stBlock, BlockDynamicLiquid dyBlock, Object stAnim, Object dyAnim) {
|
||||
this.id = id;
|
||||
this.stBlock = stBlock;
|
||||
this.dyBlock = dyBlock;
|
||||
this.stAnim = stAnim;
|
||||
this.dyAnim = dyAnim;
|
||||
}
|
||||
}
|
||||
|
||||
private static int currentId;
|
||||
|
||||
private static final List<FluidInfo> FLUIDS = Lists.newArrayList();
|
||||
private static final Map<Block, Integer> ID_MAP = Maps.newHashMap();
|
||||
|
||||
public static int getFluidMeta(BlockLiquid block) {
|
||||
return ID_MAP.get(block).intValue();
|
||||
}
|
||||
|
||||
public static BlockDynamicLiquid getFluidBlock(int meta) {
|
||||
return meta < 0 || meta >= currentId ? Blocks.flowing_water : FLUIDS.get(meta).dyBlock;
|
||||
}
|
||||
|
||||
public static BlockStaticLiquid getStaticBlock(int meta) {
|
||||
return meta < 0 || meta >= currentId ? Blocks.water : FLUIDS.get(meta).stBlock;
|
||||
}
|
||||
|
||||
public static Object getFluidAnim(int meta) {
|
||||
return FLUIDS.get(meta).dyAnim;
|
||||
}
|
||||
|
||||
public static Object getStaticAnim(int meta) {
|
||||
return FLUIDS.get(meta).stAnim;
|
||||
}
|
||||
|
||||
public static int getNumFluids() {
|
||||
return currentId;
|
||||
}
|
||||
|
||||
public static BlockStaticLiquid getStaticBlock(BlockDynamicLiquid dy) {
|
||||
return FLUIDS.get(ID_MAP.get(dy).intValue()).stBlock;
|
||||
}
|
||||
|
||||
public static BlockDynamicLiquid getDynamicBlock(BlockStaticLiquid st) {
|
||||
return FLUIDS.get(ID_MAP.get(st).intValue()).dyBlock;
|
||||
}
|
||||
|
||||
static void registerFluid(BlockStaticLiquid stBlock, BlockDynamicLiquid dyBlock, Object stAnim, Object dyAnim) {
|
||||
FluidInfo info = new FluidInfo(currentId++, stBlock, dyBlock, stAnim, dyAnim);
|
||||
FLUIDS.add(info);
|
||||
ID_MAP.put(stBlock, info.id);
|
||||
ID_MAP.put(dyBlock, info.id);
|
||||
}
|
||||
}
|
|
@ -15,6 +15,9 @@ import common.block.foliage.BlockFlower;
|
|||
import common.block.foliage.BlockLeaves;
|
||||
import common.block.foliage.BlockSapling;
|
||||
import common.block.foliage.BlockTallGrass;
|
||||
import common.block.liquid.BlockDynamicLiquid;
|
||||
import common.block.liquid.BlockLiquid;
|
||||
import common.block.liquid.BlockStaticLiquid;
|
||||
import common.block.natural.BlockOre;
|
||||
import common.block.tech.BlockButton;
|
||||
import common.block.tech.BlockTNT;
|
||||
|
@ -30,6 +33,7 @@ import common.item.Item;
|
|||
import common.item.ItemAmmo;
|
||||
import common.item.ItemAppleGold;
|
||||
import common.item.ItemArmor;
|
||||
import common.item.ItemArrow;
|
||||
import common.item.ItemAxe;
|
||||
import common.item.ItemBanHammer;
|
||||
import common.item.ItemBanner;
|
||||
|
@ -107,6 +111,7 @@ import common.item.ItemShovel;
|
|||
import common.item.ItemStack;
|
||||
import common.item.ItemStick;
|
||||
import common.item.ItemSword;
|
||||
import common.item.ItemTNT;
|
||||
import common.item.ItemTiny;
|
||||
import common.item.ItemWall;
|
||||
import common.item.ItemWeatherToken;
|
||||
|
@ -254,7 +259,7 @@ public abstract class ItemRegistry {
|
|||
registerBlock(button, new ItemButton(button));
|
||||
}
|
||||
for(BlockTNT tnt : BlockTNT.TNTS) {
|
||||
registerBlock(tnt, new ItemBlock(tnt).setColor(TextColor.RED));
|
||||
registerBlock(tnt, new ItemTNT(tnt));
|
||||
}
|
||||
|
||||
for(BlockFlower flower : BlockFlower.FLOWERS) {
|
||||
|
@ -287,15 +292,15 @@ public abstract class ItemRegistry {
|
|||
|
||||
Item bucket = (new ItemBucket(null, false)).setDisplay("Eimer");
|
||||
registerItem("bucket", bucket);
|
||||
for(int z = 0; z < FluidRegistry.getNumFluids(); z++) {
|
||||
registerItem(BlockRegistry.getNameFromBlock(FluidRegistry.getStaticBlock(z)) +
|
||||
"_bucket", new ItemBucket(FluidRegistry.getFluidBlock(z), false).setDisplay("Eimer")
|
||||
for(Pair<BlockStaticLiquid, BlockDynamicLiquid> liquid : BlockLiquid.LIQUIDS) {
|
||||
registerItem(BlockRegistry.getNameFromBlock(liquid.first()) +
|
||||
"_bucket", new ItemBucket(liquid.second(), false).setDisplay("Eimer")
|
||||
.setContainerItem(bucket));
|
||||
}
|
||||
registerItem("recursive_bucket", (new ItemBucket(null, true)).setDisplay("Unendlicher Eimer"));
|
||||
for(int z = 0; z < FluidRegistry.getNumFluids(); z++) {
|
||||
registerItem("recursive_" + BlockRegistry.getNameFromBlock(FluidRegistry.getStaticBlock(z)) +
|
||||
"_bucket", new ItemBucket(FluidRegistry.getFluidBlock(z), true).setDisplay("Flutender Eimer"));
|
||||
for(Pair<BlockStaticLiquid, BlockDynamicLiquid> liquid : BlockLiquid.LIQUIDS) {
|
||||
registerItem("recursive_" + BlockRegistry.getNameFromBlock(liquid.first()) +
|
||||
"_bucket", new ItemBucket(liquid.second(), true).setDisplay("Flutender Eimer"));
|
||||
}
|
||||
registerItem("milk_bucket", (new ItemBucketMilk()).setDisplay("Milch").setContainerItem(bucket));
|
||||
|
||||
|
@ -340,7 +345,7 @@ public abstract class ItemRegistry {
|
|||
registerItem("bow", (new ItemBow()).setDisplay("Bogen"));
|
||||
registerItem("boltgun", (new ItemBoltgun()).setDisplay("Bolter"));
|
||||
registerItem("bolt", (new ItemAmmo(5, 1.0f, 128)).setDisplay("Bolter-Munition"));
|
||||
registerItem("arrow", (new Item()).setDisplay("Pfeil").setTab(CheatTab.COMBAT).setMaxAmount(128));
|
||||
registerItem("arrow", (new ItemArrow()).setDisplay("Pfeil").setTab(CheatTab.COMBAT).setMaxAmount(128));
|
||||
Item coal = (new Item()).setDisplay("Kohle").setTab(CheatTab.METALS);
|
||||
registerItem("coal", coal);
|
||||
registerItem("charcoal", (new Item()).setDisplay("Holzkohle").setTab(CheatTab.METALS));
|
||||
|
@ -518,9 +523,9 @@ public abstract class ItemRegistry {
|
|||
((BlockOre)BlockRegistry.getRegisteredBlock("black_quartz_ore")).setDropItem(new ItemStack(bquartz), 3);
|
||||
|
||||
|
||||
for(int z = 0; z < FluidRegistry.getNumFluids(); z++) {
|
||||
registerSpecial(FluidRegistry.getFluidBlock(z));
|
||||
registerSpecial(FluidRegistry.getStaticBlock(z));
|
||||
for(Pair<BlockStaticLiquid, BlockDynamicLiquid> liquid : BlockLiquid.LIQUIDS) {
|
||||
registerSpecial(liquid.second());
|
||||
registerSpecial(liquid.first());
|
||||
}
|
||||
registerSpecial(Blocks.air);
|
||||
registerSpecial(Blocks.cocoa);
|
||||
|
|
13
common/src/main/java/common/init/LiquidType.java
Normal file
13
common/src/main/java/common/init/LiquidType.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package common.init;
|
||||
|
||||
import common.block.Material;
|
||||
|
||||
public enum LiquidType {
|
||||
COLD(Material.COLD), HOT(Material.HOT), WATER(Material.WATER), LAVA(Material.LAVA);
|
||||
|
||||
public final Material material;
|
||||
|
||||
private LiquidType(Material material) {
|
||||
this.material = material;
|
||||
}
|
||||
}
|
|
@ -11,6 +11,5 @@ public abstract class Registry {
|
|||
CraftingRegistry.register();
|
||||
SmeltingRegistry.register();
|
||||
EntityRegistry.register();
|
||||
DispenserRegistry.register();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,13 +7,17 @@ import java.util.Set;
|
|||
import common.attributes.Attribute;
|
||||
import common.attributes.UsageSlot;
|
||||
import common.block.Block;
|
||||
import common.block.tech.BlockDispenser;
|
||||
import common.collect.Sets;
|
||||
import common.color.TextColor;
|
||||
import common.entity.Entity;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.entity.types.EntityLiving;
|
||||
import common.entity.types.IProjectile;
|
||||
import common.model.Model;
|
||||
import common.model.ModelProvider;
|
||||
import common.model.Transforms;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.ExtMath;
|
||||
import common.util.Facing;
|
||||
|
@ -299,4 +303,25 @@ public class Item
|
|||
public String getSprite(EntityNPC player, ItemStack stack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
BlockDispenser.dispense(world, 6.0, facing, position, stack.splitStack(1));
|
||||
return stack;
|
||||
}
|
||||
|
||||
protected final ItemStack dispenseProjectile(World world, Facing facing, ItemStack stack, IProjectile entity) {
|
||||
return this.dispenseProjectile(world, facing, stack, entity, 1.1f, 6.0f);
|
||||
}
|
||||
|
||||
protected final ItemStack dispenseProjectile(World world, Facing facing, ItemStack stack, IProjectile entity, float velocity, float inaccuracy) {
|
||||
entity.setThrowableHeading((double)facing.getFrontOffsetX(), (double)((float)facing.getFrontOffsetY() + 0.1F),
|
||||
(double)facing.getFrontOffsetZ(), velocity, inaccuracy);
|
||||
world.spawnEntityInWorld((Entity)entity);
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public int getDispenseSoundId() {
|
||||
return 1000;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,64 +6,23 @@ import java.util.function.Predicate;
|
|||
|
||||
import common.attributes.Attribute;
|
||||
import common.attributes.UsageSlot;
|
||||
import common.block.tech.BlockDispenser;
|
||||
import common.dispenser.BehaviorDefaultDispenseItem;
|
||||
import common.dispenser.IBehaviorDispenseItem;
|
||||
import common.dispenser.IBlockSource;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.entity.types.EntityLiving;
|
||||
import common.init.DispenserRegistry;
|
||||
import common.init.ToolMaterial;
|
||||
import common.model.Model;
|
||||
import common.model.ModelProvider;
|
||||
import common.model.Transforms;
|
||||
import common.tags.TagObject;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.BoundingBox;
|
||||
import common.util.Facing;
|
||||
import common.util.Vec3;
|
||||
import common.world.World;
|
||||
|
||||
public class ItemArmor extends Item
|
||||
{
|
||||
// public static final String[] EMPTY_SLOT_NAMES = new String[] {"items/empty_armor_slot_helmet", "items/empty_armor_slot_chestplate", "items/empty_armor_slot_leggings", "items/empty_armor_slot_boots"};
|
||||
private static final IBehaviorDispenseItem dispenserBehavior = new BehaviorDefaultDispenseItem()
|
||||
{
|
||||
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
BlockPos blockpos = source.getBlockPos().offset(BlockDispenser.getFacing(source.getBlockMetadata()));
|
||||
int i = blockpos.getX();
|
||||
int j = blockpos.getY();
|
||||
int k = blockpos.getZ();
|
||||
BoundingBox axisalignedbb = new BoundingBox((double)i, (double)j, (double)k, (double)(i + 1), (double)(j + 1), (double)(k + 1));
|
||||
List<EntityLiving> list = source.getWorld().<EntityLiving>getEntitiesWithinAABB(EntityLiving.class, axisalignedbb, new Predicate<EntityLiving>() {
|
||||
public boolean test(EntityLiving entity) {
|
||||
return entity.isEntityAlive() && entity instanceof EntityNPC &&
|
||||
entity.getItem(ItemArmor.getArmorPosition(stack)) != null; // || entitylivingbase.isPlayer());
|
||||
}
|
||||
});
|
||||
|
||||
if (list.size() > 0)
|
||||
{
|
||||
EntityLiving entitylivingbase = (EntityLiving)list.get(0);
|
||||
int l = entitylivingbase.isPlayer() ? 1 : 0;
|
||||
int i1 = ItemArmor.getArmorPosition(stack);
|
||||
ItemStack itemstack = stack.copy();
|
||||
itemstack.size = 1;
|
||||
entitylivingbase.setItem(i1 - l, itemstack);
|
||||
|
||||
// if (entitylivingbase instanceof EntityLiving)
|
||||
// {
|
||||
// ((EntityLiving)entitylivingbase).setDropChance(i1, 2.0F);
|
||||
// }
|
||||
|
||||
--stack.size;
|
||||
return stack;
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.dispenseStack(source, stack);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stores the armor type: 0 is helmet, 1 is plate, 2 is legs and 3 is boots
|
||||
|
@ -92,7 +51,6 @@ public class ItemArmor extends Item
|
|||
this.damageReduceAmount = material.getDamageReduction(armorType);
|
||||
this.setMaxDamage(material.getDurability(armorType));
|
||||
this.setTab(CheatTab.COMBAT);
|
||||
DispenserRegistry.REGISTRY.putObject(this, dispenserBehavior);
|
||||
}
|
||||
|
||||
public int getColorFromItemStack(ItemStack stack, int renderPass)
|
||||
|
@ -315,4 +273,35 @@ public class ItemArmor extends Item
|
|||
// return 4;
|
||||
// }
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
BlockPos pos = blockpos.offset(facing);
|
||||
int i = pos.getX();
|
||||
int j = pos.getY();
|
||||
int k = pos.getZ();
|
||||
BoundingBox axisalignedbb = new BoundingBox((double)i, (double)j, (double)k, (double)(i + 1), (double)(j + 1), (double)(k + 1));
|
||||
List<EntityLiving> list = world.<EntityLiving>getEntitiesWithinAABB(EntityLiving.class, axisalignedbb, new Predicate<EntityLiving>() {
|
||||
public boolean test(EntityLiving entity) {
|
||||
return entity.isEntityAlive() && entity instanceof EntityNPC &&
|
||||
entity.getItem(getArmorPosition(stack)) != null;
|
||||
}
|
||||
});
|
||||
|
||||
if (list.size() > 0)
|
||||
{
|
||||
EntityLiving entitylivingbase = (EntityLiving)list.get(0);
|
||||
int l = entitylivingbase.isPlayer() ? 1 : 0;
|
||||
int i1 = getArmorPosition(stack);
|
||||
ItemStack itemstack = stack.copy();
|
||||
itemstack.size = 1;
|
||||
entitylivingbase.setItem(i1 - l, itemstack);
|
||||
|
||||
--stack.size;
|
||||
return stack;
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.dispenseStack(world, source, position, blockpos, facing, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
20
common/src/main/java/common/item/ItemArrow.java
Normal file
20
common/src/main/java/common/item/ItemArrow.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package common.item;
|
||||
|
||||
import common.entity.projectile.EntityArrow;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.Vec3;
|
||||
import common.world.World;
|
||||
|
||||
public class ItemArrow extends Item {
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
EntityArrow arrow = new EntityArrow(world, position.xCoord, position.yCoord, position.zCoord);
|
||||
arrow.canBePickedUp = 1;
|
||||
return this.dispenseProjectile(world, facing, stack, arrow);
|
||||
}
|
||||
|
||||
public int getDispenseSoundId() {
|
||||
return 1002;
|
||||
}
|
||||
}
|
|
@ -2,13 +2,16 @@ package common.item;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import common.block.Block;
|
||||
import common.entity.Entity;
|
||||
import common.entity.item.EntityBoat;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.init.Blocks;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.BoundingBox;
|
||||
import common.util.ExtMath;
|
||||
import common.util.Facing;
|
||||
import common.util.HitPosition;
|
||||
import common.util.Vec3;
|
||||
import common.world.World;
|
||||
|
@ -110,4 +113,32 @@ public class ItemBoat extends Item
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
double d0 = blockpos.getX() + 0.5 + (double)((float)facing.getFrontOffsetX() * 1.125F);
|
||||
double d1 = blockpos.getY() + 0.5 + (double)((float)facing.getFrontOffsetY() * 1.125F);
|
||||
double d2 = blockpos.getZ() + 0.5 + (double)((float)facing.getFrontOffsetZ() * 1.125F);
|
||||
BlockPos pos = blockpos.offset(facing);
|
||||
Block block = world.getState(pos).getBlock();
|
||||
double d3;
|
||||
|
||||
if (block.getMaterial().isColdLiquid())
|
||||
{
|
||||
d3 = 1.0D;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (block != Blocks.air || !world.getState(pos.down()).getBlock().getMaterial().isColdLiquid())
|
||||
{
|
||||
return super.dispenseStack(world, source, position, blockpos, facing, stack);
|
||||
}
|
||||
|
||||
d3 = 0.0D;
|
||||
}
|
||||
|
||||
EntityBoat entityboat = new EntityBoat(world, d0, d1 + d3, d2);
|
||||
world.spawnEntityInWorld(entityboat);
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,15 +16,18 @@ import common.collect.Sets;
|
|||
import common.entity.npc.EntityNPC;
|
||||
import common.init.BlockRegistry;
|
||||
import common.init.Blocks;
|
||||
import common.init.FluidRegistry;
|
||||
import common.init.ItemRegistry;
|
||||
import common.init.Items;
|
||||
import common.init.SoundEvent;
|
||||
import common.model.Model;
|
||||
import common.model.ModelProvider;
|
||||
import common.model.ParticleType;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.tileentity.TileEntityDispenser;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.HitPosition;
|
||||
import common.util.Vec3;
|
||||
import common.util.Vec3i;
|
||||
import common.world.State;
|
||||
import common.world.World;
|
||||
|
@ -52,7 +55,7 @@ public class ItemBucket extends Item
|
|||
Queue<BlockPos> queue = new ArrayDeque<BlockPos>();
|
||||
Set<BlockPos> visited = new HashSet<BlockPos>();
|
||||
List<Vec3i> dirs = new ArrayList<Vec3i>();
|
||||
Set<Block> blocks = liquid == null ? null : Sets.newHashSet(FluidRegistry.getDynamicBlock(liquid), liquid, Blocks.air);
|
||||
Set<Block> blocks = liquid == null ? null : Sets.newHashSet(liquid.getFlowingBlock(), liquid, Blocks.air);
|
||||
State state = (liquid == null ? Blocks.air : liquid).getState();
|
||||
int max = World.MAX_SIZE_Y - 1;
|
||||
|
||||
|
@ -176,8 +179,7 @@ public class ItemBucket extends Item
|
|||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
Block block = iblockstate.getBlock();
|
||||
return this.fillBucket(itemStackIn, playerIn, new ItemStack(
|
||||
ItemRegistry.getRegisteredItem(BlockRegistry.getNameFromBlock(block instanceof BlockDynamicLiquid
|
||||
? FluidRegistry.getStaticBlock((BlockDynamicLiquid)block) : block) +
|
||||
ItemRegistry.getRegisteredItem(BlockRegistry.getNameFromFluid((BlockLiquid)block) +
|
||||
"_bucket")));
|
||||
}
|
||||
}
|
||||
|
@ -272,7 +274,7 @@ public class ItemBucket extends Item
|
|||
|
||||
if(this.recursive) {
|
||||
if(!worldIn.client)
|
||||
setRecursive((AWorldServer)worldIn, pos, 4, FluidRegistry.getStaticBlock(this.liquid));
|
||||
setRecursive((AWorldServer)worldIn, pos, 4, this.liquid.getStaticBlock());
|
||||
}
|
||||
else {
|
||||
worldIn.setState(pos, this.liquid.getState(), 3);
|
||||
|
@ -319,29 +321,52 @@ public class ItemBucket extends Item
|
|||
public Model getModel(ModelProvider provider, String name) {
|
||||
return this.recursive ? provider.getModel(this.getTransform(), name.substring("recursive_".length())) : super.getModel(provider, name);
|
||||
}
|
||||
|
||||
// public ItemMeshDefinition getMesher() {
|
||||
// return this.fillBlock != null ? null : new ItemMeshDefinition()
|
||||
// {
|
||||
// public String getModelLocation(ItemStack stack)
|
||||
// {
|
||||
// return "item/fluid_bucket#0" + '#' + "inventory";
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
//
|
||||
// public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
|
||||
// if(this.fillBlock != null)
|
||||
// super.getRenderItems(itemIn, subItems);
|
||||
// else
|
||||
// subItems.add(new ItemStack(itemIn, 1, 0));
|
||||
// }
|
||||
|
||||
// public Model getModel(String name, int meta) {
|
||||
// if(this.empty)
|
||||
// return super.getModel(name, meta);
|
||||
// else
|
||||
// return provider.getModel(this.getTransform(), meta < 0 || meta >= FluidRegistry.getNumFluids() ? "bucket" :
|
||||
// (BlockRegistry.getNameFromBlock(FluidRegistry.getStaticBlock(meta)) + "_bucket"));
|
||||
// }
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
if(this.recursive)
|
||||
return super.dispenseStack(world, source, position, blockpos, facing, stack);
|
||||
if(this.liquid == null) {
|
||||
BlockPos pos = blockpos.offset(facing);
|
||||
State iblockstate = world.getState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
Material material = block.getMaterial();
|
||||
Item item;
|
||||
if (material.isLiquid() && block instanceof BlockLiquid && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
|
||||
{
|
||||
item = ItemRegistry.getRegisteredItem(BlockRegistry.getNameFromFluid((BlockLiquid)block) + "_bucket");
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.dispenseStack(world, source, position, blockpos, facing, stack);
|
||||
}
|
||||
|
||||
world.setBlockToAir(pos);
|
||||
|
||||
if (--stack.size == 0)
|
||||
{
|
||||
stack.setItem(item);
|
||||
stack.size = 1;
|
||||
}
|
||||
else if (source instanceof TileEntityDispenser dispenser && dispenser.addItemStack(new ItemStack(item)) < 0)
|
||||
{
|
||||
super.dispenseStack(world, source, position, blockpos, facing, new ItemStack(item));
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
else {
|
||||
BlockPos pos = blockpos.offset(facing);
|
||||
|
||||
if (this.tryPlaceContainedLiquid(world, pos))
|
||||
{
|
||||
stack.setItem(Items.bucket);
|
||||
stack.size = 1;
|
||||
return stack;
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.dispenseStack(world, source, position, blockpos, facing, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,11 @@ import common.init.SoundEvent;
|
|||
import common.model.Model;
|
||||
import common.model.ModelProvider;
|
||||
import common.model.Transforms;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.Pair;
|
||||
import common.util.Vec3;
|
||||
import common.world.World;
|
||||
|
||||
public class ItemDie extends Item
|
||||
|
@ -85,4 +89,12 @@ public class ItemDie extends Item
|
|||
return provider.getModel(provider.getModel("items/die_d" + this.sides + "_side").add().nswe()
|
||||
.du("items/die_d" + this.sides + "_top"), this.getTransform());
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
return this.dispenseProjectile(world, facing, stack, new EntityDie(world, position.xCoord, position.yCoord, position.zCoord, this.sides), 0.275f, 30.0f);
|
||||
}
|
||||
|
||||
public int getDispenseSoundId() {
|
||||
return 1002;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import common.tileentity.TileEntity;
|
|||
import common.tileentity.TileEntityBeacon;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.Vec3;
|
||||
import common.world.State;
|
||||
import common.world.World;
|
||||
import common.world.AWorldServer;
|
||||
|
@ -217,4 +218,29 @@ public class ItemDye extends Item
|
|||
public Model getModel(ModelProvider provider, String name) {
|
||||
return provider.getModel(this.getTransform(), "dye_" + this.color.getName());
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
if(this.color != DyeColor.WHITE)
|
||||
return super.dispenseStack(world, source, position, blockpos, facing, stack);
|
||||
BlockPos pos = blockpos = blockpos.offset(facing);
|
||||
|
||||
if (applyBonemeal(stack, world, pos))
|
||||
{
|
||||
if (!world.client)
|
||||
{
|
||||
world.playAuxSFX(2005, pos, 0);
|
||||
}
|
||||
world.playAuxSFX(1000, blockpos, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
world.playAuxSFX(1001, blockpos, 0);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public int getDispenseSoundId() {
|
||||
return this.color == DyeColor.WHITE ? 0 : super.getDispenseSoundId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,11 @@ package common.item;
|
|||
import common.entity.npc.EntityNPC;
|
||||
import common.entity.projectile.EntityDynamite;
|
||||
import common.init.SoundEvent;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.ExtMath;
|
||||
import common.util.Facing;
|
||||
import common.util.Vec3;
|
||||
import common.world.World;
|
||||
|
||||
public class ItemDynamite extends Item {
|
||||
|
@ -33,4 +37,12 @@ public class ItemDynamite extends Item {
|
|||
world.spawnEntityInWorld(new EntityDynamite(world, player, this.power));
|
||||
return stack;
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
return this.dispenseProjectile(world, facing, stack, new EntityDynamite(world, position.xCoord, position.yCoord, position.zCoord, this.power));
|
||||
}
|
||||
|
||||
public int getDispenseSoundId() {
|
||||
return 1002;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,10 @@ package common.item;
|
|||
import common.entity.npc.EntityNPC;
|
||||
import common.entity.projectile.EntityEgg;
|
||||
import common.init.SoundEvent;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.Vec3;
|
||||
import common.world.World;
|
||||
|
||||
public class ItemEgg extends Item
|
||||
|
@ -32,4 +36,12 @@ public class ItemEgg extends Item
|
|||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
return this.dispenseProjectile(world, facing, stack, new EntityEgg(world, position.xCoord, position.yCoord, position.zCoord));
|
||||
}
|
||||
|
||||
public int getDispenseSoundId() {
|
||||
return 1002;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,10 @@ package common.item;
|
|||
import common.entity.item.EntityXpBottle;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.init.SoundEvent;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.Vec3;
|
||||
import common.world.World;
|
||||
|
||||
public class ItemExpBottle extends Item
|
||||
|
@ -37,4 +41,12 @@ public class ItemExpBottle extends Item
|
|||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
return this.dispenseProjectile(world, facing, stack, new EntityXpBottle(world, position.xCoord, position.yCoord, position.zCoord), 1.375f, 3.0f);
|
||||
}
|
||||
|
||||
public int getDispenseSoundId() {
|
||||
return 1002;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,10 @@ import common.collect.Lists;
|
|||
import common.entity.item.EntityFireworks;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.tags.TagObject;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.Vec3;
|
||||
import common.world.World;
|
||||
|
||||
public class ItemFirework extends Item
|
||||
|
@ -76,7 +78,17 @@ public class ItemFirework extends Item
|
|||
}
|
||||
}
|
||||
|
||||
// public Set<String> getValidTags() {
|
||||
// return Sets.newHashSet("Fireworks");
|
||||
// }
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
double d0 = blockpos.getX() + 0.5 + (double)facing.getFrontOffsetX();
|
||||
double d1 = (double)blockpos.getY() + 0.2;
|
||||
double d2 = blockpos.getZ() + 0.5 + (double)facing.getFrontOffsetZ();
|
||||
EntityFireworks entityfireworkrocket = new EntityFireworks(world, d0, d1, d2, stack);
|
||||
world.spawnEntityInWorld(entityfireworkrocket);
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public int getDispenseSoundId() {
|
||||
return 1002;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,15 @@ import java.util.List;
|
|||
|
||||
import common.color.DyeColor;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.entity.projectile.EntityFireCharge;
|
||||
import common.model.Model;
|
||||
import common.model.ModelProvider;
|
||||
import common.tags.TagObject;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.Vec3;
|
||||
import common.world.World;
|
||||
|
||||
public class ItemFireworkCharge extends Item
|
||||
{
|
||||
|
@ -181,4 +187,20 @@ public class ItemFireworkCharge extends Item
|
|||
public Model getModel(ModelProvider provider, String name) {
|
||||
return provider.getModel(this.getTransform(), "firework_charge", "firework_charge_overlay");
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
double d0 = position.xCoord + (double)((float)facing.getFrontOffsetX() * 0.3F);
|
||||
double d1 = position.yCoord + (double)((float)facing.getFrontOffsetY() * 0.3F);
|
||||
double d2 = position.zCoord + (double)((float)facing.getFrontOffsetZ() * 0.3F);
|
||||
double d3 = world.rand.gaussian() * 0.05D + (double)facing.getFrontOffsetX();
|
||||
double d4 = world.rand.gaussian() * 0.05D + (double)facing.getFrontOffsetY();
|
||||
double d5 = world.rand.gaussian() * 0.05D + (double)facing.getFrontOffsetZ();
|
||||
world.spawnEntityInWorld(new EntityFireCharge(world, d0, d1, d2, d3, d4, d5));
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public int getDispenseSoundId() {
|
||||
return 1009;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package common.item;
|
||||
|
||||
import common.block.natural.BlockFire;
|
||||
import common.block.tech.BlockTNT;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.init.Blocks;
|
||||
import common.init.SoundEvent;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.Vec3;
|
||||
import common.world.World;
|
||||
|
||||
public class ItemFlintAndSteel extends Item
|
||||
|
@ -46,4 +49,35 @@ public class ItemFlintAndSteel extends Item
|
|||
public boolean isMagnetic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
BlockPos pos = blockpos = blockpos.offset(facing);
|
||||
|
||||
if (world.isAirBlock(pos))
|
||||
{
|
||||
world.setState(pos, this.fireBlock.getState());
|
||||
|
||||
if (stack.attemptDamageItem(1, world.rand))
|
||||
{
|
||||
stack.size = 0;
|
||||
}
|
||||
world.playAuxSFX(1000, blockpos, 0);
|
||||
}
|
||||
else if (world.getState(pos).getBlock() instanceof BlockTNT tnt)
|
||||
{
|
||||
tnt.onBlockDestroyedByPlayer(world, pos, tnt.getState().withProperty(BlockTNT.EXPLODE, true));
|
||||
world.setBlockToAir(pos);
|
||||
world.playAuxSFX(1000, blockpos, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
world.playAuxSFX(1001, blockpos, 0);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public int getDispenseSoundId() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,83 +1,18 @@
|
|||
package common.item;
|
||||
|
||||
import common.block.tech.BlockDispenser;
|
||||
import common.block.tech.BlockRailBase;
|
||||
import common.dispenser.BehaviorDefaultDispenseItem;
|
||||
import common.dispenser.IBehaviorDispenseItem;
|
||||
import common.dispenser.IBlockSource;
|
||||
import common.entity.item.EntityCart;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.init.Blocks;
|
||||
import common.init.DispenserRegistry;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.Vec3;
|
||||
import common.world.State;
|
||||
import common.world.World;
|
||||
|
||||
public class ItemMinecart extends Item
|
||||
{
|
||||
private static final IBehaviorDispenseItem dispenserMinecartBehavior = new BehaviorDefaultDispenseItem()
|
||||
{
|
||||
private final BehaviorDefaultDispenseItem behaviourDefaultDispenseItem = new BehaviorDefaultDispenseItem();
|
||||
public ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
Facing enumfacing = BlockDispenser.getFacing(source.getBlockMetadata());
|
||||
World world = source.getWorld();
|
||||
double d0 = source.getX() + (double)enumfacing.getFrontOffsetX() * 1.125D;
|
||||
double d1 = Math.floor(source.getY()) + (double)enumfacing.getFrontOffsetY();
|
||||
double d2 = source.getZ() + (double)enumfacing.getFrontOffsetZ() * 1.125D;
|
||||
BlockPos blockpos = source.getBlockPos().offset(enumfacing);
|
||||
State iblockstate = world.getState(blockpos);
|
||||
BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = iblockstate.getBlock() instanceof BlockRailBase ? (BlockRailBase.EnumRailDirection)iblockstate.getValue(((BlockRailBase)iblockstate.getBlock()).getShapeProperty()) : BlockRailBase.EnumRailDirection.NORTH_SOUTH;
|
||||
double d3;
|
||||
|
||||
if (BlockRailBase.isRailBlock(iblockstate))
|
||||
{
|
||||
if (blockrailbase$enumraildirection.isAscending())
|
||||
{
|
||||
d3 = 0.6D;
|
||||
}
|
||||
else
|
||||
{
|
||||
d3 = 0.1D;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iblockstate.getBlock() != Blocks.air || !BlockRailBase.isRailBlock(world.getState(blockpos.down())))
|
||||
{
|
||||
return this.behaviourDefaultDispenseItem.dispense(source, stack);
|
||||
}
|
||||
|
||||
State iblockstate1 = world.getState(blockpos.down());
|
||||
BlockRailBase.EnumRailDirection blockrailbase$enumraildirection1 = iblockstate1.getBlock() instanceof BlockRailBase ? (BlockRailBase.EnumRailDirection)iblockstate1.getValue(((BlockRailBase)iblockstate1.getBlock()).getShapeProperty()) : BlockRailBase.EnumRailDirection.NORTH_SOUTH;
|
||||
|
||||
if (enumfacing != Facing.DOWN && blockrailbase$enumraildirection1.isAscending())
|
||||
{
|
||||
d3 = -0.4D;
|
||||
}
|
||||
else
|
||||
{
|
||||
d3 = -0.9D;
|
||||
}
|
||||
}
|
||||
|
||||
EntityCart entityminecart = EntityCart.getMinecart(world, d0, d1 + d3, d2, ((ItemMinecart)stack.getItem()).minecartType);
|
||||
|
||||
if (stack.hasDisplayName())
|
||||
{
|
||||
entityminecart.setCustomNameTag(stack.getDisplayName());
|
||||
}
|
||||
|
||||
world.spawnEntityInWorld(entityminecart);
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
protected void playDispenseSound(IBlockSource source)
|
||||
{
|
||||
source.getWorld().playAuxSFX(1000, source.getBlockPos(), 0);
|
||||
}
|
||||
};
|
||||
private final EntityCart.EnumMinecartType minecartType;
|
||||
|
||||
public ItemMinecart(EntityCart.EnumMinecartType type)
|
||||
|
@ -86,7 +21,6 @@ public class ItemMinecart extends Item
|
|||
this.minecartType = type;
|
||||
this.setTab(CheatTab.SPAWNERS);
|
||||
// if(type != EntityMinecart.EnumMinecartType.COMMAND_BLOCK)
|
||||
DispenserRegistry.REGISTRY.putObject(this, dispenserMinecartBehavior);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,4 +75,56 @@ public class ItemMinecart extends Item
|
|||
public boolean isMagnetic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
double d0 = blockpos.getX() + 0.5 + (double)facing.getFrontOffsetX() * 1.125D;
|
||||
double d1 = Math.floor(blockpos.getY() + 0.5) + (double)facing.getFrontOffsetY();
|
||||
double d2 = blockpos.getZ() + 0.5 + (double)facing.getFrontOffsetZ() * 1.125D;
|
||||
BlockPos pos = blockpos.offset(facing);
|
||||
State iblockstate = world.getState(pos);
|
||||
BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = iblockstate.getBlock() instanceof BlockRailBase ? (BlockRailBase.EnumRailDirection)iblockstate.getValue(((BlockRailBase)iblockstate.getBlock()).getShapeProperty()) : BlockRailBase.EnumRailDirection.NORTH_SOUTH;
|
||||
double d3;
|
||||
|
||||
if (BlockRailBase.isRailBlock(iblockstate))
|
||||
{
|
||||
if (blockrailbase$enumraildirection.isAscending())
|
||||
{
|
||||
d3 = 0.6D;
|
||||
}
|
||||
else
|
||||
{
|
||||
d3 = 0.1D;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iblockstate.getBlock() != Blocks.air || !BlockRailBase.isRailBlock(world.getState(pos.down())))
|
||||
{
|
||||
return super.dispenseStack(world, source, position, blockpos, facing, stack);
|
||||
}
|
||||
|
||||
State iblockstate1 = world.getState(pos.down());
|
||||
BlockRailBase.EnumRailDirection blockrailbase$enumraildirection1 = iblockstate1.getBlock() instanceof BlockRailBase ? (BlockRailBase.EnumRailDirection)iblockstate1.getValue(((BlockRailBase)iblockstate1.getBlock()).getShapeProperty()) : BlockRailBase.EnumRailDirection.NORTH_SOUTH;
|
||||
|
||||
if (facing != Facing.DOWN && blockrailbase$enumraildirection1.isAscending())
|
||||
{
|
||||
d3 = -0.4D;
|
||||
}
|
||||
else
|
||||
{
|
||||
d3 = -0.9D;
|
||||
}
|
||||
}
|
||||
|
||||
EntityCart entityminecart = EntityCart.getMinecart(world, d0, d1 + d3, d2, this.minecartType);
|
||||
|
||||
if (stack.hasDisplayName())
|
||||
{
|
||||
entityminecart.setCustomNameTag(stack.getDisplayName());
|
||||
}
|
||||
|
||||
world.spawnEntityInWorld(entityminecart);
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,12 @@ import common.init.EntityRegistry;
|
|||
import common.init.UniverseRegistry;
|
||||
import common.model.Model;
|
||||
import common.model.ModelProvider;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.ExtMath;
|
||||
import common.util.Facing;
|
||||
import common.util.HitPosition;
|
||||
import common.util.Vec3;
|
||||
import common.world.State;
|
||||
import common.world.World;
|
||||
|
||||
|
@ -229,4 +231,16 @@ public class ItemMonsterPlacer extends Item
|
|||
public Model getModel(ModelProvider provider, String name) {
|
||||
return provider.getModel(this.getTransform(), "spawn_egg", "spawn_egg_overlay");
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack)
|
||||
{
|
||||
double d0 = blockpos.getX() + 0.5 + (double)facing.getFrontOffsetX();
|
||||
double d1 = blockpos.getY() + 0.2;
|
||||
double d2 = blockpos.getZ() + 0.5 + (double)facing.getFrontOffsetZ();
|
||||
Entity entity = spawnCreature(world, this.entityId, d0, d1, d2, false);
|
||||
if (entity instanceof EntityLiving && stack.hasDisplayName())
|
||||
((EntityLiving)entity).setCustomNameTag(stack.getDisplayName());
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,10 +16,12 @@ import common.init.EntityRegistry;
|
|||
import common.init.UniverseRegistry;
|
||||
import common.model.Model;
|
||||
import common.model.ModelProvider;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.ExtMath;
|
||||
import common.util.Facing;
|
||||
import common.util.HitPosition;
|
||||
import common.util.Vec3;
|
||||
import common.world.State;
|
||||
import common.world.World;
|
||||
|
||||
|
@ -214,4 +216,16 @@ public class ItemNpcSpawner extends Item
|
|||
public Model getModel(ModelProvider provider, String name) {
|
||||
return provider.getModel(this.getTransform(), "npc_spawner", "npc_spawner_overlay");
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack)
|
||||
{
|
||||
double d0 = blockpos.getX() + 0.5 + (double)facing.getFrontOffsetX();
|
||||
double d1 = blockpos.getY() + 0.2;
|
||||
double d2 = blockpos.getZ() + 0.5 + (double)facing.getFrontOffsetZ();
|
||||
Entity entity = spawnNpc(world, this.spawned, d0, d1, d2, false);
|
||||
if (entity instanceof EntityLiving && stack.hasDisplayName())
|
||||
((EntityLiving)entity).setCustomNameTag(stack.getDisplayName());
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,10 @@ import common.model.ModelProvider;
|
|||
import common.potion.Potion;
|
||||
import common.potion.PotionEffect;
|
||||
import common.potion.PotionHelper;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.Vec3;
|
||||
import common.world.World;
|
||||
|
||||
public class ItemPotion extends Item
|
||||
|
@ -344,4 +348,14 @@ public class ItemPotion extends Item
|
|||
public Model getModel(ModelProvider provider, String name) {
|
||||
return provider.getModel(this.getTransform(), "potion_overlay", this.isSplashPotion() ? "potion_bottle_splash" : "potion_bottle_drinkable");
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
if(this.isSplashPotion())
|
||||
return this.dispenseProjectile(world, facing, stack, new EntityPotion(world, position.xCoord, position.yCoord, position.zCoord, stack.copy()), 1.375f, 3.0f);
|
||||
return super.dispenseStack(world, source, position, blockpos, facing, stack);
|
||||
}
|
||||
|
||||
public int getDispenseSoundId() {
|
||||
return this.isSplashPotion() ? 1002 : super.getDispenseSoundId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,10 @@ package common.item;
|
|||
import common.entity.npc.EntityNPC;
|
||||
import common.entity.projectile.EntitySnowball;
|
||||
import common.init.SoundEvent;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.Vec3;
|
||||
import common.world.World;
|
||||
|
||||
public class ItemSnowball extends Item
|
||||
|
@ -32,4 +36,12 @@ public class ItemSnowball extends Item
|
|||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
return this.dispenseProjectile(world, facing, stack, new EntitySnowball(world, position.xCoord, position.yCoord, position.zCoord));
|
||||
}
|
||||
|
||||
public int getDispenseSoundId() {
|
||||
return 1002;
|
||||
}
|
||||
}
|
||||
|
|
31
common/src/main/java/common/item/ItemTNT.java
Normal file
31
common/src/main/java/common/item/ItemTNT.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package common.item;
|
||||
|
||||
import common.block.tech.BlockTNT;
|
||||
import common.color.TextColor;
|
||||
import common.entity.item.EntityTnt;
|
||||
import common.entity.types.EntityLiving;
|
||||
import common.init.SoundEvent;
|
||||
import common.tileentity.TileEntity;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Facing;
|
||||
import common.util.Vec3;
|
||||
import common.world.World;
|
||||
|
||||
public class ItemTNT extends ItemBlock {
|
||||
private final int power;
|
||||
|
||||
public ItemTNT(BlockTNT block) {
|
||||
super(block);
|
||||
this.power = block.getExplosionPower();
|
||||
this.setColor(TextColor.RED);
|
||||
}
|
||||
|
||||
public ItemStack dispenseStack(World world, TileEntity source, Vec3 position, BlockPos blockpos, Facing facing, ItemStack stack) {
|
||||
blockpos = blockpos.offset(facing);
|
||||
EntityTnt entitytntprimed = new EntityTnt(world, (double)blockpos.getX() + 0.5D, (double)blockpos.getY(), (double)blockpos.getZ() + 0.5D, (EntityLiving)null, this.power);
|
||||
world.spawnEntityInWorld(entitytntprimed);
|
||||
world.playSoundAtEntity(entitytntprimed, SoundEvent.FUSE, 1.0F);
|
||||
--stack.size;
|
||||
return stack;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue