inline dispenser registry
This commit is contained in:
parent
e3e9598fc5
commit
039a7d7d9e
31 changed files with 491 additions and 809 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,6 +30,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 +108,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 +256,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) {
|
||||
|
@ -340,7 +342,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));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,12 @@ 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;
|
||||
|
@ -319,29 +323,54 @@ 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.getNameFromBlock(block instanceof BlockDynamicLiquid
|
||||
? FluidRegistry.getStaticBlock((BlockDynamicLiquid)block) : 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