base mod created
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package net.minecraft.dispenser;
|
||||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.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, (EnumFacing)source.getBlockState().getValue(BlockDispenser.FACING));
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispense the specified stack, play the dispense sound and spawn particles.
|
||||
*/
|
||||
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
EnumFacing enumfacing = (EnumFacing)source.getBlockState().getValue(BlockDispenser.FACING);
|
||||
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, EnumFacing facing, IPosition position)
|
||||
{
|
||||
double d0 = position.getX();
|
||||
double d1 = position.getY();
|
||||
double d2 = position.getZ();
|
||||
|
||||
if (facing.getAxis() == EnumFacing.Axis.Y)
|
||||
{
|
||||
d1 = d1 - 0.125D;
|
||||
}
|
||||
else
|
||||
{
|
||||
d1 = d1 - 0.15625D;
|
||||
}
|
||||
|
||||
EntityItem entityitem = new EntityItem(worldIn, d0, d1, d2, stack);
|
||||
double d3 = worldIn.rand.nextDouble() * 0.1D + 0.2D;
|
||||
entityitem.motionX = (double)facing.getFrontOffsetX() * d3;
|
||||
entityitem.motionY = 0.20000000298023224D;
|
||||
entityitem.motionZ = (double)facing.getFrontOffsetZ() * d3;
|
||||
entityitem.motionX += worldIn.rand.nextGaussian() * 0.007499999832361937D * (double)speed;
|
||||
entityitem.motionY += worldIn.rand.nextGaussian() * 0.007499999832361937D * (double)speed;
|
||||
entityitem.motionZ += worldIn.rand.nextGaussian() * 0.007499999832361937D * (double)speed;
|
||||
worldIn.spawnEntity(entityitem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Play the dispense sound from the specified block.
|
||||
*/
|
||||
protected void playDispenseSound(IBlockSource source)
|
||||
{
|
||||
source.getWorld().playEvent(1000, source.getBlockPos(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Order clients to display dispense particles from the specified block and facing.
|
||||
*/
|
||||
protected void spawnDispenseParticles(IBlockSource source, EnumFacing facingIn)
|
||||
{
|
||||
source.getWorld().playEvent(2000, source.getBlockPos(), this.getWorldEventDataFrom(facingIn));
|
||||
}
|
||||
|
||||
private int getWorldEventDataFrom(EnumFacing facingIn)
|
||||
{
|
||||
return facingIn.getFrontOffsetX() + 1 + (facingIn.getFrontOffsetZ() + 1) * 3;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package net.minecraft.dispenser;
|
||||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.IProjectile;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.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);
|
||||
EnumFacing enumfacing = (EnumFacing)source.getBlockState().getValue(BlockDispenser.FACING);
|
||||
IProjectile iprojectile = this.getProjectileEntity(world, iposition, stack);
|
||||
iprojectile.shoot((double)enumfacing.getFrontOffsetX(), (double)((float)enumfacing.getFrontOffsetY() + 0.1F), (double)enumfacing.getFrontOffsetZ(), this.getProjectileVelocity(), this.getProjectileInaccuracy());
|
||||
world.spawnEntity((Entity)iprojectile);
|
||||
stack.shrink(1);
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Play the dispense sound from the specified block.
|
||||
*/
|
||||
protected void playDispenseSound(IBlockSource source)
|
||||
{
|
||||
source.getWorld().playEvent(1002, source.getBlockPos(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the projectile entity spawned by this dispense behavior.
|
||||
*/
|
||||
protected abstract IProjectile getProjectileEntity(World worldIn, IPosition position, ItemStack stackIn);
|
||||
|
||||
protected float getProjectileInaccuracy()
|
||||
{
|
||||
return 6.0F;
|
||||
}
|
||||
|
||||
protected float getProjectileVelocity()
|
||||
{
|
||||
return 1.1F;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package net.minecraft.dispenser;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IBehaviorDispenseItem
|
||||
{
|
||||
IBehaviorDispenseItem DEFAULT_BEHAVIOR = new IBehaviorDispenseItem()
|
||||
{
|
||||
/**
|
||||
* Dispenses the specified ItemStack from a dispenser.
|
||||
*/
|
||||
public ItemStack dispense(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispenses the specified ItemStack from a dispenser.
|
||||
*/
|
||||
ItemStack dispense(IBlockSource source, ItemStack stack);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package net.minecraft.dispenser;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public interface IBlockSource extends ILocatableSource
|
||||
{
|
||||
double getX();
|
||||
|
||||
double getY();
|
||||
|
||||
double getZ();
|
||||
|
||||
BlockPos getBlockPos();
|
||||
|
||||
/**
|
||||
* Gets the block state of this position and returns it.
|
||||
* @return Block state in this position
|
||||
*/
|
||||
IBlockState getBlockState();
|
||||
|
||||
<T extends TileEntity> T getBlockTileEntity();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package net.minecraft.dispenser;
|
||||
|
||||
public interface ILocatableSource extends ILocation
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.minecraft.dispenser;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface ILocation extends IPosition
|
||||
{
|
||||
World getWorld();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.minecraft.dispenser;
|
||||
|
||||
public interface IPosition
|
||||
{
|
||||
double getX();
|
||||
|
||||
double getY();
|
||||
|
||||
double getZ();
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.minecraft.dispenser;
|
||||
|
||||
public class PositionImpl implements IPosition
|
||||
{
|
||||
protected final double x;
|
||||
protected final double y;
|
||||
protected final double z;
|
||||
|
||||
public PositionImpl(double xCoord, double yCoord, double zCoord)
|
||||
{
|
||||
this.x = xCoord;
|
||||
this.y = yCoord;
|
||||
this.z = zCoord;
|
||||
}
|
||||
|
||||
public double getX()
|
||||
{
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public double getY()
|
||||
{
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public double getZ()
|
||||
{
|
||||
return this.z;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Auto generated package-info by MCP
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package net.minecraft.dispenser;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
Reference in New Issue
Block a user