initial commit

This commit is contained in:
Sen 2025-03-11 00:23:54 +01:00 committed by Sen
parent 3c9ee26b06
commit 22186c33b9
1458 changed files with 282792 additions and 0 deletions

View file

@ -0,0 +1,27 @@
package game.tileentity;
import game.inventory.IInventory;
import game.world.World;
public interface IHopper extends IInventory
{
/**
* Returns the worldObj for this tileEntity.
*/
World getWorld();
/**
* Gets the world X position for this hopper entity.
*/
double getXPos();
/**
* Gets the world Y position for this hopper entity.
*/
double getYPos();
/**
* Gets the world Z position for this hopper entity.
*/
double getZPos();
}

View file

@ -0,0 +1,12 @@
package game.tileentity;
import game.entity.npc.EntityNPC;
import game.inventory.Container;
import game.inventory.InventoryPlayer;
public interface IInteractionObject extends IWorldNameable
{
Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn);
String getGuiID();
}

View file

@ -0,0 +1,12 @@
package game.tileentity;
import game.inventory.IInventory;
public interface ILockableContainer extends IInventory, IInteractionObject
{
boolean isLocked();
void setLockCode(LockCode code);
LockCode getLockCode();
}

View file

@ -0,0 +1,6 @@
package game.tileentity;
public interface ITickable
{
void update();
}

View file

@ -0,0 +1,6 @@
package game.tileentity;
public interface IWorldNameable
{
String getCommandName();
}

View file

@ -0,0 +1,51 @@
package game.tileentity;
import game.entity.npc.EntityNPC;
import game.inventory.Container;
import game.inventory.InventoryPlayer;
public class LocalBlockIntercommunication implements IInteractionObject
{
private String guiID;
private String displayName;
public LocalBlockIntercommunication(String guiIdIn, String displayNameIn)
{
this.guiID = guiIdIn;
this.displayName = displayNameIn;
}
public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn)
{
throw new UnsupportedOperationException();
}
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
return this.displayName;
}
/**
* Returns true if this thing is named
*/
public boolean hasCustomName()
{
return true;
}
public String getGuiID()
{
return this.guiID;
}
/**
* Get the formatted ChatComponent that will be used for the sender's username in chat
*/
public String getCommandName()
{
return this.displayName;
}
}

View file

@ -0,0 +1,42 @@
package game.tileentity;
import game.nbt.NBTTagCompound;
public class LockCode
{
public static final LockCode EMPTY_CODE = new LockCode("");
private final String lock;
public LockCode(String code)
{
this.lock = code;
}
public boolean isEmpty()
{
return this.lock == null || this.lock.isEmpty();
}
public String getLock()
{
return this.lock;
}
public void toNBT(NBTTagCompound nbt)
{
nbt.setString("Lock", this.lock);
}
public static LockCode fromNBT(NBTTagCompound nbt)
{
if (nbt.hasKey("Lock", 8))
{
String s = nbt.getString("Lock");
return new LockCode(s);
}
else
{
return EMPTY_CODE;
}
}
}

View file

@ -0,0 +1,108 @@
package game.tileentity;
import game.nbt.NBTTagCompound;
public class MachineResource {
public static enum Type {
INPUT, OUTPUT, FUEL, CONTROL;
}
private final Type type;
private final String name;
private int amount;
private int capacity;
private int undercharge;
private int overcharge;
private int entropy;
public MachineResource(Type type, String name, int cap, int under, int over) {
this.type = type;
this.name = name;
this.capacity = cap;
this.undercharge = under;
this.overcharge = over;
}
public void readFromNbt(NBTTagCompound tag) {
this.amount = tag.getInteger("Amount");
this.capacity = tag.getInteger("Capacity");
this.undercharge = tag.getInteger("Under");
this.overcharge = tag.getInteger("Over");
this.entropy = tag.getInteger("Entropy");
}
public void writeToNbt(NBTTagCompound tag) {
tag.setInteger("Amount", this.amount);
tag.setInteger("Capacity", this.capacity);
tag.setInteger("Under", this.undercharge);
tag.setInteger("Over", this.overcharge);
tag.setInteger("Entropy", this.entropy);
}
public void setValue(int value) {
this.amount = value;
}
public void setUndercharge(int value) {
this.undercharge = value;
}
public void setOvercharge(int value) {
this.overcharge = value;
}
public void setCapacity(int value) {
this.capacity = value;
}
public boolean take(int value, boolean over) {
if((over ? this.undercharge : 0) + this.amount < value)
return false;
this.amount -= value;
return true;
}
public boolean add(int value, int border, boolean over) {
if(this.amount + (border >= 1 ? border : value) > (over ? this.overcharge : 0) + this.capacity)
return false;
int max = (over ? this.overcharge : 0) + this.capacity - this.amount;
if(value > max) {
this.entropy += value - max;
value = max;
}
this.amount += value;
return true;
}
public int getValue() {
return this.amount;
}
public int getUndercharge() {
return this.undercharge;
}
public int getOvercharge() {
return this.overcharge;
}
public int getCapacity() {
return this.capacity;
}
public int getEntropy() {
return this.entropy;
}
public void resetEntropy() {
this.entropy = 0;
}
public void reset() {
this.entropy = this.amount = 0;
}
public boolean isAtCapacity(boolean over) {
return this.amount >= (this.capacity + (over ? this.overcharge : 0));
}
}

View file

@ -0,0 +1,227 @@
package game.tileentity;
import game.Log;
import game.block.Block;
import game.init.Blocks;
import game.init.TileRegistry;
import game.nbt.NBTTagCompound;
import game.network.Packet;
import game.world.BlockPos;
import game.world.State;
import game.world.World;
public abstract class TileEntity
{
public static enum EnumCreateEntityType
{
IMMEDIATE,
QUEUED,
CHECK;
}
/** the instance of the world the tile entity is in. */
protected World worldObj;
protected BlockPos pos = BlockPos.ORIGIN;
protected boolean tileEntityInvalid;
private int blockMetadata = -1;
/** the Block type that this TileEntity is contained within */
protected Block blockType;
/**
* Returns the worldObj for this tileEntity.
*/
public World getWorld()
{
return this.worldObj;
}
/**
* Sets the worldObj for this tileEntity.
*/
public void setWorldObj(World worldIn)
{
this.worldObj = worldIn;
}
/**
* Returns true if the worldObj isn't null.
*/
public boolean hasWorldObj()
{
return this.worldObj != null;
}
public void readFromNBT(NBTTagCompound compound)
{
this.pos = new BlockPos(compound.getInteger("x"), compound.getInteger("y"), compound.getInteger("z"));
}
public void writeToNBT(NBTTagCompound compound)
{
String s = (String)TileRegistry.classToNameMap.get(this.getClass());
if (s == null)
{
throw new RuntimeException(this.getClass() + " is missing a mapping! This is a bug!");
}
else
{
compound.setString("id", s);
compound.setInteger("x", this.pos.getX());
compound.setInteger("y", this.pos.getY());
compound.setInteger("z", this.pos.getZ());
}
}
/**
* Creates a new entity and loads its data from the specified NBT.
*/
public static TileEntity createAndLoadEntity(NBTTagCompound nbt)
{
TileEntity tileentity = null;
try
{
Class <? extends TileEntity > oclass = (Class)TileRegistry.nameToClassMap.get(nbt.getString("id"));
if (oclass != null)
{
tileentity = (TileEntity)oclass.newInstance();
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
if (tileentity != null)
{
tileentity.readFromNBT(nbt);
}
else
{
Log.JNI.warn("Ignoriere Block-Objekt mit ID " + nbt.getString("id"));
}
return tileentity;
}
public int getBlockMetadata()
{
if (this.blockMetadata == -1)
{
State iblockstate = this.worldObj.getState(this.pos);
this.blockMetadata = iblockstate.getBlock().getMetaFromState(iblockstate);
}
return this.blockMetadata;
}
/**
* For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it
* hasn't changed and skip it.
*/
public void markDirty()
{
if (this.worldObj != null)
{
State iblockstate = this.worldObj.getState(this.pos);
this.blockMetadata = iblockstate.getBlock().getMetaFromState(iblockstate);
this.worldObj.markChunkDirty(this.pos, this);
if (this.getBlockType() != Blocks.air)
{
this.worldObj.updateComparatorOutputLevel(this.pos, this.getBlockType());
}
}
}
/**
* Returns the square of the distance between this entity and the passed in coordinates.
*/
public double getDistanceSq(double x, double y, double z)
{
double d0 = (double)this.pos.getX() + 0.5D - x;
double d1 = (double)this.pos.getY() + 0.5D - y;
double d2 = (double)this.pos.getZ() + 0.5D - z;
return d0 * d0 + d1 * d1 + d2 * d2;
}
public double getMaxRenderDistanceSquared()
{
return 4096.0D;
}
public BlockPos getPos()
{
return this.pos;
}
/**
* Gets the block type at the location of this entity (client-only).
*/
public Block getBlockType()
{
if (this.blockType == null)
{
this.blockType = this.worldObj.getState(this.pos).getBlock();
}
return this.blockType;
}
/**
* Allows for a specialized description packet to be created. This is often used to sync tile entity data from the
* server to the client easily. For example this is used by signs to synchronise the text to be displayed.
*/
public Packet getDescriptionPacket()
{
return null;
}
public boolean isInvalid()
{
return this.tileEntityInvalid;
}
/**
* invalidates a tile entity
*/
public void invalidate()
{
this.tileEntityInvalid = true;
}
/**
* validates a tile entity
*/
public boolean validate()
{
this.tileEntityInvalid = false;
return false;
}
public boolean receiveClientEvent(int id, int type)
{
return false;
}
public void updateContainingBlockInfo()
{
this.blockType = null;
this.blockMetadata = -1;
}
public void setPos(BlockPos posIn)
{
this.pos = posIn;
}
// public boolean hasSpecialNBT()
// {
// return false;
// }
public abstract int getColor();
}

View file

@ -0,0 +1,346 @@
package game.tileentity;
import java.util.List;
import game.block.BlockFlower;
import game.collect.Lists;
import game.color.DyeColor;
import game.init.Blocks;
import game.init.Items;
import game.item.ItemStack;
import game.nbt.NBTTagCompound;
import game.nbt.NBTTagList;
import game.network.Packet;
import game.packet.S35PacketUpdateTileEntity;
public class TileEntityBanner extends TileEntity
{
private int baseColor;
/** A list of all the banner patterns. */
private NBTTagList patterns;
private boolean field_175119_g;
private List<TileEntityBanner.EnumBannerPattern> patternList;
private List<DyeColor> colorList;
/**
* This is a String representation of this banners pattern and color lists, used for texture caching.
*/
private String patternResourceLocation;
public void setItemValues(ItemStack stack)
{
this.patterns = null;
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("BlockEntityTag", 10))
{
NBTTagCompound nbttagcompound = stack.getTagCompound().getCompoundTag("BlockEntityTag");
if (nbttagcompound.hasKey("Patterns"))
{
this.patterns = (NBTTagList)nbttagcompound.getTagList("Patterns", 10).copy();
}
if (nbttagcompound.hasKey("Base", 99))
{
this.baseColor = nbttagcompound.getInteger("Base");
}
else
{
this.baseColor = stack.getMetadata() & 15;
}
}
else
{
this.baseColor = stack.getMetadata() & 15;
}
this.patternList = null;
this.colorList = null;
this.patternResourceLocation = "";
this.field_175119_g = true;
}
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
setBaseColorAndPatterns(compound, this.baseColor, this.patterns);
}
public static void setBaseColorAndPatterns(NBTTagCompound compound, int baseColorIn, NBTTagList patternsIn)
{
compound.setInteger("Base", baseColorIn);
if (patternsIn != null)
{
compound.setTag("Patterns", patternsIn);
}
}
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
this.baseColor = compound.getInteger("Base");
this.patterns = compound.getTagList("Patterns", 10);
this.patternList = null;
this.colorList = null;
this.patternResourceLocation = null;
this.field_175119_g = true;
}
/**
* Allows for a specialized description packet to be created. This is often used to sync tile entity data from the
* server to the client easily. For example this is used by signs to synchronise the text to be displayed.
*/
public Packet getDescriptionPacket()
{
return new S35PacketUpdateTileEntity(this);
}
public int getBaseColor()
{
return this.baseColor;
}
public static int getBaseColor(ItemStack stack)
{
NBTTagCompound nbttagcompound = stack.getSubCompound("BlockEntityTag", false);
return nbttagcompound != null && nbttagcompound.hasKey("Base") ? nbttagcompound.getInteger("Base") : stack.getMetadata();
}
/**
* Retrieves the amount of patterns stored on an ItemStack. If the tag does not exist this value will be 0.
*/
public static int getPatterns(ItemStack stack)
{
NBTTagCompound nbttagcompound = stack.getSubCompound("BlockEntityTag", false);
return nbttagcompound != null && nbttagcompound.hasKey("Patterns") ? nbttagcompound.getTagList("Patterns", 10).tagCount() : 0;
}
public List<TileEntityBanner.EnumBannerPattern> getPatternList()
{
this.initializeBannerData();
return this.patternList;
}
public NBTTagList getPatterns()
{
return this.patterns;
}
public List<DyeColor> getColorList()
{
this.initializeBannerData();
return this.colorList;
}
public String getPatternResourceLocation()
{
this.initializeBannerData();
return this.patternResourceLocation;
}
/**
* Establishes all of the basic properties for the banner. This will also apply the data from the tile entities nbt
* tag compounds.
*/
private void initializeBannerData()
{
if (this.patternList == null || this.colorList == null || this.patternResourceLocation == null)
{
if (!this.field_175119_g)
{
this.patternResourceLocation = "";
}
else
{
this.patternList = Lists.<TileEntityBanner.EnumBannerPattern>newArrayList();
this.colorList = Lists.<DyeColor>newArrayList();
this.patternList.add(TileEntityBanner.EnumBannerPattern.BASE);
this.colorList.add(DyeColor.byDyeDamage(this.baseColor));
this.patternResourceLocation = "b" + this.baseColor;
if (this.patterns != null)
{
for (int i = 0; i < this.patterns.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = this.patterns.getCompoundTagAt(i);
TileEntityBanner.EnumBannerPattern tileentitybanner$enumbannerpattern = TileEntityBanner.EnumBannerPattern.getPatternByID(nbttagcompound.getString("Pattern"));
if (tileentitybanner$enumbannerpattern != null)
{
this.patternList.add(tileentitybanner$enumbannerpattern);
int j = nbttagcompound.getInteger("Color");
this.colorList.add(DyeColor.byDyeDamage(j));
this.patternResourceLocation = this.patternResourceLocation + tileentitybanner$enumbannerpattern.getPatternID() + j;
}
}
}
}
}
}
public int getColor() {
return 0xffffff;
}
/**
* Removes all the banner related data from a provided instance of ItemStack.
*/
public static void removeBannerData(ItemStack stack)
{
NBTTagCompound nbttagcompound = stack.getSubCompound("BlockEntityTag", false);
if (nbttagcompound != null && nbttagcompound.hasKey("Patterns", 9))
{
NBTTagList nbttaglist = nbttagcompound.getTagList("Patterns", 10);
if (nbttaglist.tagCount() > 0)
{
nbttaglist.removeTag(nbttaglist.tagCount() - 1);
if (nbttaglist.hasNoTags())
{
stack.getTagCompound().removeTag("BlockEntityTag");
if (stack.getTagCompound().hasNoTags())
{
stack.setTagCompound((NBTTagCompound)null);
}
}
}
}
}
public static enum EnumBannerPattern
{
BASE("base", "b", "%s Banner", 0, false),
SQUARE_BOTTOM_LEFT("square_bottom_left", "bl", "%s rechtes Untereck", 0, false, " ", " ", "# "),
SQUARE_BOTTOM_RIGHT("square_bottom_right", "br", "%s linkes Untereck", 0, false, " ", " ", " #"),
SQUARE_TOP_LEFT("square_top_left", "tl", "%s rechtes Obereck", 0, false, "# ", " ", " "),
SQUARE_TOP_RIGHT("square_top_right", "tr", "%s linkes Obereck", 0, false, " #", " ", " "),
STRIPE_BOTTOM("stripe_bottom", "bs", "%s Bannerfuß", 1, false, " ", " ", "###"),
STRIPE_TOP("stripe_top", "ts", "%s Bannerhaupt", 0, false, "###", " ", " "),
STRIPE_LEFT("stripe_left", "ls", "%s rechte Flanke", -1, false, "# ", "# ", "# "),
STRIPE_RIGHT("stripe_right", "rs", "%s linke Flanke", -1, false, " #", " #", " #"),
STRIPE_CENTER("stripe_center", "cs", "%s Pfahl", 1, false, " # ", " # ", " # "),
STRIPE_MIDDLE("stripe_middle", "ms", "%s Balken", 1, false, " ", "###", " "),
STRIPE_DOWNRIGHT("stripe_downright", "drs", "%s Schrägbalken", 1, false, "# ", " # ", " #"),
STRIPE_DOWNLEFT("stripe_downleft", "dls", "%s Schräglinksbalken", 1, false, " #", " # ", "# "),
STRIPE_SMALL("small_stripes", "ss", "Vier %s Pfähle", 1, true, "# #", "# #", " "),
CROSS("cross", "cr", "%s Andreaskreuz", 0, false, "# #", " # ", "# #"),
STRAIGHT_CROSS("straight_cross", "sc", "%s Kreuz", 0, false, " # ", "###", " # "),
TRIANGLE_BOTTOM("triangle_bottom", "bt", "%s halbe Spitze", -1, false, " ", " # ", "# #"),
TRIANGLE_TOP("triangle_top", "tt", "%s gestürzte halbe Spitze", -1, false, "# #", " # ", " "),
TRIANGLES_BOTTOM("triangles_bottom", "bts", "%s gespickelter Bannerfuß", 1, false, " ", "# #", " # "),
TRIANGLES_TOP("triangles_top", "tts", "%s gespickeltes Bannerhaupt", 0, false, " # ", "# #", " "),
DIAGONAL_LEFT("diagonal_left", "ld", "%s schräglinks geteilt", null, false, "## ", "# ", " "),
DIAGONAL_RIGHT("diagonal_up_right", "rd", "%s schräglinks geteilt (Invertiert)", null, false, " ", " #", " ##"),
DIAGONAL_LEFT_MIRROR("diagonal_up_left", "lud", "%s schrägrechts geteilt (Invertiert)", null, false, " ", "# ", "## "),
DIAGONAL_RIGHT_MIRROR("diagonal_right", "rud", "%s schrägrechts geteilt", null, false, " ##", " #", " "),
CIRCLE_MIDDLE("circle", "mc", "%s Kugel", -1, false, " ", " # ", " "),
RHOMBUS_MIDDLE("rhombus", "mr", "%s Raute", -1, false, " # ", "# #", " # "),
HALF_VERTICAL("half_vertical", "vh", "Rechts %s gespalten", null, true, "## ", "## ", "## "),
HALF_HORIZONTAL("half_horizontal", "hh", "Oben %s geteilt", null, true, "###", "###", " "),
HALF_VERTICAL_MIRROR("half_vertical_right", "vhr", "Links %s gespalten", null, true, " ##", " ##", " ##"),
HALF_HORIZONTAL_MIRROR("half_horizontal_bottom", "hhb", "Unten %s geteilt", null, true, " ", "###", "###"),
BORDER("border", "bo", "%s Bord", 1, false, "###", "# #", "###"),
CURLY_BORDER("curly_border", "cbo", "%s Spickelbord", 1, false, new ItemStack(Blocks.vine)),
RUNE("rune", "run", "%s Rune", -1, false, new ItemStack(Items.golden_apple, 1, 0)),
GRADIENT("gradient", "gra", "%s Farbverlauf", 1, false, "# #", " # ", " # "),
GRADIENT_UP("gradient_up", "gru", "%s Farbverlauf (Invertiert)", 1, false, " # ", " # ", "# #"),
BRICKS("bricks", "bri", "Feld %s gemauert", null, true, new ItemStack(Blocks.brick_block)),
SKULL("skull", "sku", "%s Schädel", 1, false, new ItemStack(Items.skull, 1, 0)),
FLOWER("flower", "flo", "%s Blume", -1, false, new ItemStack(Blocks.flower, 1, BlockFlower.EnumFlowerType.OXEYE_DAISY.getMeta())),
THING("thing", "thi", "%s <???>", 0, false, new ItemStack(Items.golden_apple, 1, 1));
private String patternName;
private String patternID;
private String display;
private Integer displayType;
private boolean displayLower;
private String[] craftingLayers;
private ItemStack patternCraftingStack;
private EnumBannerPattern(String name, String id, String display, Integer displayType, boolean displayLower)
{
this.craftingLayers = new String[3];
this.patternName = name;
this.patternID = id;
this.display = display;
this.displayType = displayType;
}
private EnumBannerPattern(String name, String id, String display, Integer displayType, boolean displayLower, ItemStack craftingItem)
{
this(name, id, display, displayType, displayLower);
this.patternCraftingStack = craftingItem;
}
private EnumBannerPattern(String name, String id, String display, Integer displayType, boolean displayLower, String craftingTop, String craftingMid, String craftingBot)
{
this(name, id, display, displayType, displayLower);
this.craftingLayers[0] = craftingTop;
this.craftingLayers[1] = craftingMid;
this.craftingLayers[2] = craftingBot;
}
public String getPatternName()
{
return this.patternName;
}
public String getPatternID()
{
return this.patternID;
}
public String getDisplay()
{
return this.display;
}
public Integer getDisplayType()
{
return this.displayType;
}
public boolean isColorLowercase()
{
return this.displayLower;
}
public String[] getCraftingLayers()
{
return this.craftingLayers;
}
public boolean hasValidCrafting()
{
return this.patternCraftingStack != null || this.craftingLayers[0] != null;
}
public boolean hasCraftingStack()
{
return this.patternCraftingStack != null;
}
public ItemStack getCraftingStack()
{
return this.patternCraftingStack;
}
public static TileEntityBanner.EnumBannerPattern getPatternByID(String id)
{
for (TileEntityBanner.EnumBannerPattern tileentitybanner$enumbannerpattern : values())
{
if (tileentitybanner$enumbannerpattern.patternID.equals(id))
{
return tileentitybanner$enumbannerpattern;
}
}
return null;
}
}
}

View file

@ -0,0 +1,557 @@
package game.tileentity;
import java.util.List;
import game.block.Block;
import game.color.DyeColor;
import game.entity.types.EntityLiving;
import game.init.Blocks;
import game.nbt.NBTTagCompound;
import game.network.Packet;
import game.packet.S35PacketUpdateTileEntity;
import game.potion.Potion;
import game.potion.PotionEffect;
import game.world.BlockPos;
import game.world.BoundingBox;
import game.world.State;
import game.world.World;
import game.world.WorldServer;
public class TileEntityBeacon extends TileEntity implements ITickable
{
/** List of effects that Beacon can apply */
public static final Potion[][] effectsList = new Potion[][] {{Potion.moveSpeed, Potion.digSpeed}, {Potion.resistance, Potion.jump}, {Potion.damageBoost}, {Potion.regeneration}};
// private final List<TileEntityBeacon.BeamSegment> beamSegments = Lists.<TileEntityBeacon.BeamSegment>newArrayList();
// private long lastRenderUpdate;
// private float charge;
private boolean isComplete;
/** Level of this beacon's pyramid. */
private int levels = -1;
/** Primary potion effect given by this beacon. */
private int primaryEffect;
/** Secondary potion effect given by this beacon. */
private int secondaryEffect;
/** Item given to this beacon as payment. */
// private ItemStack payment;
private String customName;
private DyeColor beamColor = DyeColor.WHITE;
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
if (!this.worldObj.client && ((WorldServer)this.worldObj).getTime() % 80L == 0L)
{
this.updateBeacon();
}
// else if (this.worldObj.client && this.worldObj.getDayTime() % 20L == 0L)
// {
// this.updateBeacon();
// }
}
public void updateBeacon()
{
if(!this.worldObj.client)
// this.updateSegmentColors();
// else
this.updateSegment();
}
private void addEffectsToPlayers()
{
if (this.isComplete && this.levels > 0 && this.primaryEffect > 0)
{
double d0 = (double)(this.levels * 10 + 10);
int i = 0;
if (this.levels >= 4 && this.primaryEffect == this.secondaryEffect)
{
i = 1;
}
int j = this.pos.getX();
int k = this.pos.getY();
int l = this.pos.getZ();
BoundingBox axisalignedbb = (new BoundingBox((double)j, (double)k, (double)l, (double)(j + 1), (double)(k + 1), (double)(l + 1))).expand(d0, d0, d0).addCoord(0.0D, (double)World.HEIGHT, 0.0D);
List<EntityLiving> list = this.worldObj.<EntityLiving>getEntitiesWithinAABB(EntityLiving.class, axisalignedbb);
for (EntityLiving entityplayer : list)
{
entityplayer.addEffect(new PotionEffect(this.primaryEffect, 180, i, true, true));
}
if (this.levels >= 4 && this.primaryEffect != this.secondaryEffect && this.secondaryEffect > 0)
{
for (EntityLiving entityplayer1 : list)
{
entityplayer1.addEffect(new PotionEffect(this.secondaryEffect, 180, 0, true, true));
}
}
}
}
private void calculateLevels() {
int j = this.pos.getX();
int k = this.pos.getY();
int l = this.pos.getZ();
if (this.isComplete)
{
for (int l1 = 1; l1 <= 4; this.levels = l1++)
{
int i2 = k - l1;
if (i2 < 0)
{
break;
}
boolean flag1 = true;
for (int j1 = j - l1; j1 <= j + l1 && flag1; ++j1)
{
for (int k1 = l - l1; k1 <= l + l1; ++k1)
{
Block block = this.worldObj.getState(new BlockPos(j1, i2, k1)).getBlock();
if (block != Blocks.emerald_block && block != Blocks.gold_block && block != Blocks.diamond_block && block != Blocks.iron_block)
{
flag1 = false;
break;
}
}
}
if (!flag1)
{
break;
}
}
if (this.levels == 0)
{
this.isComplete = false;
}
}
}
private void updateSegment()
{
// int i = this.levels;
int j = this.pos.getX();
int k = this.pos.getY();
int l = this.pos.getZ();
this.levels = 0;
this.isComplete = true;
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
for (int i1 = k + 1; i1 < 512; ++i1)
{
State iblockstate = this.worldObj.getState(blockpos$mutableblockpos.set(j, i1, l));
if (iblockstate.getBlock() != Blocks.stained_glass && iblockstate.getBlock() != Blocks.stained_glass_pane
&& iblockstate.getBlock().getLightOpacity() >= 15 && iblockstate.getBlock() != Blocks.bedrock) {
this.isComplete = false;
break;
}
}
this.calculateLevels();
// if (this.levels == 4 && i < this.levels)
// {
// for (EntityNPC entityplayer : this.worldObj.getEntitiesWithinAABB(EntityNPC.class, (new AxisAlignedBB((double)j, (double)k, (double)l, (double)j, (double)(k - 4), (double)l)).expand(10.0D, 5.0D, 10.0D)))
// {
// entityplayer.triggerAchievement(AchievementList.fullBeacon);
// }
// }
this.addEffectsToPlayers();
}
// private void updateSegmentColors()
// {
// int i = this.levels;
// int j = this.pos.getX();
// int k = this.pos.getY();
// int l = this.pos.getZ();
// this.levels = 0;
// this.beamSegments.clear();
// this.isComplete = true;
// TileEntityBeacon.BeamSegment tileentitybeacon$beamsegment = new TileEntityBeacon.BeamSegment(EntitySheep.getDyeRgb(DyeColor.WHITE));
// this.beamSegments.add(tileentitybeacon$beamsegment);
// boolean flag = true;
// BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
//
// for (int i1 = k + 1; i1 < 512; ++i1)
// {
// State iblockstate = this.worldObj.getState(blockpos$mutableblockpos.set(j, i1, l));
// float[] afloat;
//
// if (iblockstate.getBlock() == Blocks.stained_glass)
// {
// afloat = EntitySheep.getDyeRgb((DyeColor)iblockstate.getValue(BlockStainedGlass.COLOR));
// }
// else
// {
// if (iblockstate.getBlock() != Blocks.stained_glass_pane)
// {
// if (iblockstate.getBlock().getLightOpacity() >= 15 && iblockstate.getBlock() != Blocks.bedrock)
// {
// this.isComplete = false;
// this.beamSegments.clear();
// break;
// }
//
// tileentitybeacon$beamsegment.incrementHeight();
// continue;
// }
//
// afloat = EntitySheep.getDyeRgb((DyeColor)iblockstate.getValue(BlockStainedGlassPane.COLOR));
// }
//
// if (!flag)
// {
// afloat = new float[] {(tileentitybeacon$beamsegment.getColors()[0] + afloat[0]) / 2.0F, (tileentitybeacon$beamsegment.getColors()[1] + afloat[1]) / 2.0F, (tileentitybeacon$beamsegment.getColors()[2] + afloat[2]) / 2.0F};
// }
//
// if (Arrays.equals(afloat, tileentitybeacon$beamsegment.getColors()))
// {
// tileentitybeacon$beamsegment.incrementHeight();
// }
// else
// {
// tileentitybeacon$beamsegment = new TileEntityBeacon.BeamSegment(afloat);
// this.beamSegments.add(tileentitybeacon$beamsegment);
// }
//
// flag = false;
// }
//
// this.calculateLevels();
// }
// public List<TileEntityBeacon.BeamSegment> getBeamSegments()
// {
// return this.beamSegments;
// }
// public float shouldBeamRender()
// {
// if (!this.isComplete)
// {
// return 0.0F;
// }
// else
// {
// int delta = (int)(this.worldObj.getTime() - this.lastRenderUpdate);
// this.lastRenderUpdate = this.worldObj.getTime();
//
// if (delta > 1)
// {
// this.charge -= (float)delta / 40.0F;
//
// if (this.charge < 0.0F)
// {
// this.charge = 0.0F;
// }
// }
//
// this.charge += 0.025F;
//
// if (this.charge > 1.0F)
// {
// this.charge = 1.0F;
// }
//
// return this.charge;
// return 1.0F;
// }
// }
/**
* Allows for a specialized description packet to be created. This is often used to sync tile entity data from the
* server to the client easily. For example this is used by signs to synchronise the text to be displayed.
*/
public Packet getDescriptionPacket()
{
return new S35PacketUpdateTileEntity(this);
}
public double getMaxRenderDistanceSquared()
{
return 65536.0D;
}
private int getEffect(int id)
{
if (id >= 0 && id < Potion.POTION_TYPES.length && Potion.POTION_TYPES[id] != null)
{
Potion potion = Potion.POTION_TYPES[id];
return potion != Potion.moveSpeed && potion != Potion.digSpeed && potion != Potion.resistance && potion != Potion.jump && potion != Potion.damageBoost && potion != Potion.regeneration ? 0 : id;
}
else
{
return 0;
}
}
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
this.primaryEffect = this.getEffect(compound.getInteger("Primary"));
this.secondaryEffect = this.getEffect(compound.getInteger("Secondary"));
this.levels = compound.getInteger("Levels");
// try {
this.beamColor = DyeColor.getByName(compound.getString("Color"));
// }
// catch(IllegalArgumentException e) {
// this.beamColor = DyeColor.WHITE;
// }
}
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
compound.setInteger("Primary", this.primaryEffect);
compound.setInteger("Secondary", this.secondaryEffect);
compound.setInteger("Levels", this.levels);
compound.setString("Color", this.beamColor.getName());
}
/**
* Returns the number of slots in the inventory.
*/
// public int getSizeInventory()
// {
// return 1;
// }
/**
* Returns the stack in the given slot.
*/
// public ItemStack getStackInSlot(int index)
// {
// return index == 0 ? this.payment : null;
// }
/**
* Removes up to a specified number of items from an inventory slot and returns them in a new stack.
*/
// public ItemStack decrStackSize(int index, int count)
// {
// if (index == 0 && this.payment != null)
// {
// if (count >= this.payment.stackSize)
// {
// ItemStack itemstack = this.payment;
// this.payment = null;
// return itemstack;
// }
// else
// {
// this.payment.stackSize -= count;
// return new ItemStack(this.payment.getItem(), count, this.payment.getMetadata());
// }
// }
// else
// {
// return null;
// }
// }
//
// /**
// * Removes a stack from the given slot and returns it.
// */
// public ItemStack removeStackFromSlot(int index)
// {
// if (index == 0 && this.payment != null)
// {
// ItemStack itemstack = this.payment;
// this.payment = null;
// return itemstack;
// }
// else
// {
// return null;
// }
// }
//
// /**
// * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
// */
// public void setInventorySlotContents(int index, ItemStack stack)
// {
// if (index == 0)
// {
// this.payment = stack;
// }
// }
/**
* Get the name of this object. For players this returns their username
*/
// public String getName()
// {
// return this.hasCustomName() ? this.customName : "Leuchtfeuer";
// }
/**
* Returns true if this thing is named
*/
// public boolean hasCustomName()
// {
// return this.customName != null && this.customName.length() > 0;
// }
//
// public void setName(String name)
// {
// this.customName = name;
// }
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
// public int getInventoryStackLimit()
// {
// return 1;
// }
/**
* Do not make give this method the name canInteractWith because it clashes with Container
*/
// public boolean isUseableByPlayer(EntityNPC player)
// {
// return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
// }
//
// public void openInventory(EntityNPC player)
// {
// }
//
// public void closeInventory(EntityNPC player)
// {
// }
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
*/
// public boolean isItemValidForSlot(int index, ItemStack stack)
// {
// return stack.getItem() == Items.emerald || stack.getItem() == Items.diamond || stack.getItem() == Items.gold_ingot || stack.getItem() == Items.iron_ingot;
// }
//
// public String getGuiID()
// {
// return "beacon";
// }
//
// public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn)
// {
// return new ContainerBeacon(playerInventory, this);
// }
//
// public int getField(int id)
// {
// switch (id)
// {
// case 0:
// return this.levels;
//
// case 1:
// return this.primaryEffect;
//
// case 2:
// return this.secondaryEffect;
//
// default:
// return 0;
// }
// }
//
// public void setField(int id, int value)
// {
// switch (id)
// {
// case 0:
// this.levels = value;
// break;
//
// case 1:
// this.primaryEffect = this.func_183001_h(value);
// break;
//
// case 2:
// this.secondaryEffect = this.func_183001_h(value);
// }
// }
//
// public int getFieldCount()
// {
// return 3;
// }
//
// public void clear()
// {
// this.payment = null;
// }
public boolean receiveClientEvent(int id, int type)
{
if (id == 1)
{
this.beamColor = DyeColor.byMetadata(type);
return true;
}
else
{
return super.receiveClientEvent(id, type);
}
}
public int getColor() {
return 0xff00ff;
}
public int getBeamColor() {
return this.beamColor.getColor();
}
public void setBeamColor(DyeColor color) {
this.beamColor = color;
if(!this.worldObj.client)
this.worldObj.addBlockEvent(this.pos, this.getBlockType(), 1, color.getMetadata());
}
// public static class BeamSegment
// {
// private final float[] colors;
// private int height;
//
// public BeamSegment(float[] p_i45669_1_)
// {
// this.colors = p_i45669_1_;
// this.height = 1;
// }
//
// protected void incrementHeight()
// {
// ++this.height;
// }
//
// public float[] getColors()
// {
// return this.colors;
// }
//
// public int getHeight()
// {
// return this.height;
// }
// }
}

View file

@ -0,0 +1,452 @@
package game.tileentity;
import java.util.Arrays;
import java.util.List;
import game.block.BlockBrewingStand;
import game.entity.npc.EntityNPC;
import game.init.Items;
import game.inventory.Container;
import game.inventory.ContainerBrewingStand;
import game.inventory.ISidedInventory;
import game.inventory.InventoryPlayer;
import game.item.Item;
import game.item.ItemPotion;
import game.item.ItemStack;
import game.nbt.NBTTagCompound;
import game.nbt.NBTTagList;
import game.potion.PotionEffect;
import game.potion.PotionHelper;
import game.world.Facing;
import game.world.State;
public class TileEntityBrewingStand extends TileEntityLockable implements ITickable, ISidedInventory
{
/** an array of the input slot indices */
private static final int[] inputSlots = new int[] {3};
/** an array of the output slot indices */
private static final int[] outputSlots = new int[] {0, 1, 2};
/** The ItemStacks currently placed in the slots of the brewing stand */
private ItemStack[] brewingItemStacks = new ItemStack[4];
private int brewTime;
/**
* an integer with each bit specifying whether that slot of the stand contains a potion
*/
private boolean[] filledSlots;
/**
* used to check if the current ingredient has been removed from the brewing stand during brewing
*/
private Item ingredientID;
private String customName;
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
return this.hasCustomName() ? this.customName : "Braustand";
}
/**
* Returns true if this thing is named
*/
public boolean hasCustomName()
{
return this.customName != null && this.customName.length() > 0;
}
public void setName(String name)
{
this.customName = name;
}
/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory()
{
return this.brewingItemStacks.length;
}
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
if (this.brewTime > 0)
{
--this.brewTime;
if (this.brewTime == 0)
{
this.brewPotions();
this.markDirty();
}
else if (!this.canBrew())
{
this.brewTime = 0;
this.markDirty();
}
else if (this.ingredientID != this.brewingItemStacks[3].getItem())
{
this.brewTime = 0;
this.markDirty();
}
}
else if (this.canBrew())
{
this.brewTime = 400;
this.ingredientID = this.brewingItemStacks[3].getItem();
}
if (!this.worldObj.client)
{
boolean[] aboolean = this.func_174902_m();
if (!Arrays.equals(aboolean, this.filledSlots))
{
this.filledSlots = aboolean;
State iblockstate = this.worldObj.getState(this.getPos());
if (!(iblockstate.getBlock() instanceof BlockBrewingStand))
{
return;
}
for (int i = 0; i < BlockBrewingStand.HAS_BOTTLE.length; ++i)
{
iblockstate = iblockstate.withProperty(BlockBrewingStand.HAS_BOTTLE[i], Boolean.valueOf(aboolean[i]));
}
this.worldObj.setState(this.pos, iblockstate, 2);
}
}
}
private boolean canBrew()
{
if (this.brewingItemStacks[3] != null && this.brewingItemStacks[3].stackSize > 0)
{
ItemStack itemstack = this.brewingItemStacks[3];
if (!itemstack.getItem().isPotionIngredient(itemstack))
{
return false;
}
else
{
boolean flag = false;
for (int i = 0; i < 3; ++i)
{
if (this.brewingItemStacks[i] != null && this.brewingItemStacks[i].getItem() == Items.potion)
{
int j = this.brewingItemStacks[i].getMetadata();
int k = this.getPotionResult(j, itemstack);
if (!ItemPotion.isSplash(j) && ItemPotion.isSplash(k))
{
flag = true;
break;
}
List<PotionEffect> list = Items.potion.getEffects(j);
List<PotionEffect> list1 = Items.potion.getEffects(k);
if ((j <= 0 || list != list1) && (list == null || !list.equals(list1) && list1 != null) && j != k)
{
flag = true;
break;
}
}
}
return flag;
}
}
else
{
return false;
}
}
private void brewPotions()
{
if (this.canBrew())
{
ItemStack itemstack = this.brewingItemStacks[3];
for (int i = 0; i < 3; ++i)
{
if (this.brewingItemStacks[i] != null && this.brewingItemStacks[i].getItem() == Items.potion)
{
int j = this.brewingItemStacks[i].getMetadata();
int k = this.getPotionResult(j, itemstack);
List<PotionEffect> list = Items.potion.getEffects(j);
List<PotionEffect> list1 = Items.potion.getEffects(k);
if (j > 0 && list == list1 || list != null && (list.equals(list1) || list1 == null))
{
if (!ItemPotion.isSplash(j) && ItemPotion.isSplash(k))
{
this.brewingItemStacks[i].setItemDamage(k);
}
}
else if (j != k)
{
this.brewingItemStacks[i].setItemDamage(k);
}
}
}
if (itemstack.getItem().hasContainerItem())
{
this.brewingItemStacks[3] = new ItemStack(itemstack.getItem().getContainerItem());
}
else
{
--this.brewingItemStacks[3].stackSize;
if (this.brewingItemStacks[3].stackSize <= 0)
{
this.brewingItemStacks[3] = null;
}
}
}
}
/**
* The result of brewing a potion of the specified damage value with an ingredient itemstack.
*/
private int getPotionResult(int meta, ItemStack stack)
{
return stack == null ? meta : (stack.getItem().isPotionIngredient(stack) ? PotionHelper.applyIngredient(meta, stack.getItem().getPotionEffect(stack)) : meta);
}
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
NBTTagList nbttaglist = compound.getTagList("Items", 10);
this.brewingItemStacks = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound.getByte("Slot");
if (j >= 0 && j < this.brewingItemStacks.length)
{
this.brewingItemStacks[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
}
}
this.brewTime = compound.getShort("BrewTime");
if (compound.hasKey("CustomName", 8))
{
this.customName = compound.getString("CustomName");
}
}
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
compound.setShort("BrewTime", (short)this.brewTime);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.brewingItemStacks.length; ++i)
{
if (this.brewingItemStacks[i] != null)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte)i);
this.brewingItemStacks[i].writeToNBT(nbttagcompound);
nbttaglist.appendTag(nbttagcompound);
}
}
compound.setTag("Items", nbttaglist);
if (this.hasCustomName())
{
compound.setString("CustomName", this.customName);
}
}
/**
* Returns the stack in the given slot.
*/
public ItemStack getStackInSlot(int index)
{
return index >= 0 && index < this.brewingItemStacks.length ? this.brewingItemStacks[index] : null;
}
/**
* Removes up to a specified number of items from an inventory slot and returns them in a new stack.
*/
public ItemStack decrStackSize(int index, int count)
{
if (index >= 0 && index < this.brewingItemStacks.length)
{
ItemStack itemstack = this.brewingItemStacks[index];
this.brewingItemStacks[index] = null;
return itemstack;
}
else
{
return null;
}
}
/**
* Removes a stack from the given slot and returns it.
*/
public ItemStack removeStackFromSlot(int index)
{
if (index >= 0 && index < this.brewingItemStacks.length)
{
ItemStack itemstack = this.brewingItemStacks[index];
this.brewingItemStacks[index] = null;
return itemstack;
}
else
{
return null;
}
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
*/
public void setInventorySlotContents(int index, ItemStack stack)
{
if (index >= 0 && index < this.brewingItemStacks.length)
{
this.brewingItemStacks[index] = stack;
}
}
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
public int getInventoryStackLimit()
{
return ItemStack.MAX_SIZE;
}
/**
* Do not make give this method the name canInteractWith because it clashes with Container
*/
public boolean isUseableByPlayer(EntityNPC player)
{
return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
}
public void openInventory(EntityNPC player)
{
}
public void closeInventory(EntityNPC player)
{
}
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
*/
public boolean isItemValidForSlot(int index, ItemStack stack)
{
return index == 3 ? stack.getItem().isPotionIngredient(stack) : stack.getItem() == Items.potion || stack.getItem() == Items.glass_bottle;
}
public boolean[] func_174902_m()
{
boolean[] aboolean = new boolean[3];
for (int i = 0; i < 3; ++i)
{
if (this.brewingItemStacks[i] != null)
{
aboolean[i] = true;
}
}
return aboolean;
}
public int[] getSlotsForFace(Facing side)
{
return side == Facing.UP ? inputSlots : outputSlots;
}
/**
* Returns true if automation can insert the given item in the given slot from the given side. Args: slot, item,
* side
*/
public boolean canInsertItem(int index, ItemStack itemStackIn, Facing direction)
{
return this.isItemValidForSlot(index, itemStackIn);
}
/**
* Returns true if automation can extract the given item in the given slot from the given side. Args: slot, item,
* side
*/
public boolean canExtractItem(int index, ItemStack stack, Facing direction)
{
return true;
}
public String getGuiID()
{
return "brewing_stand";
}
public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn)
{
return new ContainerBrewingStand(playerInventory, this);
}
public int getField(int id)
{
switch (id)
{
case 0:
return this.brewTime;
default:
return 0;
}
}
public void setField(int id, int value)
{
switch (id)
{
case 0:
this.brewTime = value;
default:
}
}
public int getFieldCount()
{
return 1;
}
public void clear()
{
for (int i = 0; i < this.brewingItemStacks.length; ++i)
{
this.brewingItemStacks[i] = null;
}
}
public int getColor() {
return 0xffdf80;
}
}

View file

@ -0,0 +1,528 @@
package game.tileentity;
import game.block.Block;
import game.block.BlockChest;
import game.entity.npc.EntityNPC;
import game.init.SoundEvent;
import game.inventory.Container;
import game.inventory.ContainerChest;
import game.inventory.IInventory;
import game.inventory.InventoryLargeChest;
import game.inventory.InventoryPlayer;
import game.item.ItemStack;
import game.nbt.NBTTagCompound;
import game.nbt.NBTTagList;
import game.world.BlockPos;
import game.world.BoundingBox;
import game.world.Facing;
public class TileEntityChest extends TileEntityLockable implements ITickable, IInventory
{
private ItemStack[] chestContents = new ItemStack[27];
/** Determines if the check for adjacent chests has taken place. */
public boolean adjacentChestChecked;
/** Contains the chest tile located adjacent to this one (if any) */
public TileEntityChest adjacentChestZNeg;
/** Contains the chest tile located adjacent to this one (if any) */
public TileEntityChest adjacentChestXPos;
/** Contains the chest tile located adjacent to this one (if any) */
public TileEntityChest adjacentChestXNeg;
/** Contains the chest tile located adjacent to this one (if any) */
public TileEntityChest adjacentChestZPos;
/** The current angle of the lid (between 0 and 1) */
public float lidAngle;
/** The angle of the lid last tick */
public float prevLidAngle;
/** The number of players currently using this chest */
public int numPlayersUsing;
/** Server sync counter (once per 20 ticks) */
private int ticksSinceSync;
private int cachedChestType;
private String customName;
public TileEntityChest()
{
this.cachedChestType = -1;
}
public TileEntityChest(int chestType)
{
this.cachedChestType = chestType;
}
/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory()
{
return 27;
}
/**
* Returns the stack in the given slot.
*/
public ItemStack getStackInSlot(int index)
{
return this.chestContents[index];
}
/**
* Removes up to a specified number of items from an inventory slot and returns them in a new stack.
*/
public ItemStack decrStackSize(int index, int count)
{
if (this.chestContents[index] != null)
{
if (this.chestContents[index].stackSize <= count)
{
ItemStack itemstack1 = this.chestContents[index];
this.chestContents[index] = null;
this.markDirty();
return itemstack1;
}
else
{
ItemStack itemstack = this.chestContents[index].splitStack(count);
if (this.chestContents[index].stackSize == 0)
{
this.chestContents[index] = null;
}
this.markDirty();
return itemstack;
}
}
else
{
return null;
}
}
/**
* Removes a stack from the given slot and returns it.
*/
public ItemStack removeStackFromSlot(int index)
{
if (this.chestContents[index] != null)
{
ItemStack itemstack = this.chestContents[index];
this.chestContents[index] = null;
return itemstack;
}
else
{
return null;
}
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
*/
public void setInventorySlotContents(int index, ItemStack stack)
{
this.chestContents[index] = stack;
if (stack != null && stack.stackSize > this.getInventoryStackLimit())
{
stack.stackSize = this.getInventoryStackLimit();
}
this.markDirty();
}
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
return this.hasCustomName() ? this.customName : "Truhe";
}
/**
* Returns true if this thing is named
*/
public boolean hasCustomName()
{
return this.customName != null && this.customName.length() > 0;
}
public void setCustomName(String name)
{
this.customName = name;
}
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
NBTTagList nbttaglist = compound.getTagList("Items", 10);
this.chestContents = new ItemStack[this.getSizeInventory()];
if (compound.hasKey("CustomName", 8))
{
this.customName = compound.getString("CustomName");
}
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound.getByte("Slot") & 255;
if (j >= 0 && j < this.chestContents.length)
{
this.chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
}
}
}
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.chestContents.length; ++i)
{
if (this.chestContents[i] != null)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte)i);
this.chestContents[i].writeToNBT(nbttagcompound);
nbttaglist.appendTag(nbttagcompound);
}
}
compound.setTag("Items", nbttaglist);
if (this.hasCustomName())
{
compound.setString("CustomName", this.customName);
}
}
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
public int getInventoryStackLimit()
{
return ItemStack.MAX_SIZE;
}
/**
* Do not make give this method the name canInteractWith because it clashes with Container
*/
public boolean isUseableByPlayer(EntityNPC player)
{
return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
}
public void updateContainingBlockInfo()
{
super.updateContainingBlockInfo();
this.adjacentChestChecked = false;
}
private void func_174910_a(TileEntityChest chestTe, Facing side)
{
if (chestTe.isInvalid())
{
this.adjacentChestChecked = false;
}
else if (this.adjacentChestChecked)
{
switch (side)
{
case NORTH:
if (this.adjacentChestZNeg != chestTe)
{
this.adjacentChestChecked = false;
}
break;
case SOUTH:
if (this.adjacentChestZPos != chestTe)
{
this.adjacentChestChecked = false;
}
break;
case EAST:
if (this.adjacentChestXPos != chestTe)
{
this.adjacentChestChecked = false;
}
break;
case WEST:
if (this.adjacentChestXNeg != chestTe)
{
this.adjacentChestChecked = false;
}
}
}
}
/**
* Performs the check for adjacent chests to determine if this chest is double or not.
*/
public void checkForAdjacentChests()
{
if (!this.adjacentChestChecked)
{
this.adjacentChestChecked = true;
this.adjacentChestXNeg = this.getAdjacentChest(Facing.WEST);
this.adjacentChestXPos = this.getAdjacentChest(Facing.EAST);
this.adjacentChestZNeg = this.getAdjacentChest(Facing.NORTH);
this.adjacentChestZPos = this.getAdjacentChest(Facing.SOUTH);
}
}
protected TileEntityChest getAdjacentChest(Facing side)
{
BlockPos blockpos = this.pos.offset(side);
if (this.isChestAt(blockpos))
{
TileEntity tileentity = this.worldObj.getTileEntity(blockpos);
if (tileentity instanceof TileEntityChest)
{
TileEntityChest tileentitychest = (TileEntityChest)tileentity;
tileentitychest.func_174910_a(this, side.getOpposite());
return tileentitychest;
}
}
return null;
}
private boolean isChestAt(BlockPos posIn)
{
if (this.worldObj == null)
{
return false;
}
else
{
Block block = this.worldObj.getState(posIn).getBlock();
return block instanceof BlockChest && ((BlockChest)block).chestType == this.getChestType();
}
}
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
this.checkForAdjacentChests();
int i = this.pos.getX();
int j = this.pos.getY();
int k = this.pos.getZ();
++this.ticksSinceSync;
if (!this.worldObj.client && this.numPlayersUsing != 0 && (this.ticksSinceSync + i + j + k) % 200 == 0)
{
this.numPlayersUsing = 0;
float f = 5.0F;
for (EntityNPC entityplayer : this.worldObj.getEntitiesWithinAABB(EntityNPC.class, new BoundingBox((double)((float)i - f), (double)((float)j - f), (double)((float)k - f), (double)((float)(i + 1) + f), (double)((float)(j + 1) + f), (double)((float)(k + 1) + f))))
{
if (entityplayer.isPlayer() && entityplayer.openContainer instanceof ContainerChest)
{
IInventory iinventory = ((ContainerChest)entityplayer.openContainer).getLowerChestInventory();
if (iinventory == this || iinventory instanceof InventoryLargeChest && ((InventoryLargeChest)iinventory).isPartOfLargeChest(this))
{
++this.numPlayersUsing;
}
}
}
}
this.prevLidAngle = this.lidAngle;
float f1 = 0.1F;
if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F && this.adjacentChestZNeg == null && this.adjacentChestXNeg == null)
{
double d1 = (double)i + 0.5D;
double d2 = (double)k + 0.5D;
if (this.adjacentChestZPos != null)
{
d2 += 0.5D;
}
if (this.adjacentChestXPos != null)
{
d1 += 0.5D;
}
this.worldObj.playSound(SoundEvent.CHESTOPEN, d1, (double)j + 0.5D, d2, 0.5F, this.worldObj.rand.floatv() * 0.1F + 0.9F);
}
if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F)
{
float f2 = this.lidAngle;
if (this.numPlayersUsing > 0)
{
this.lidAngle += f1;
}
else
{
this.lidAngle -= f1;
}
if (this.lidAngle > 1.0F)
{
this.lidAngle = 1.0F;
}
float f3 = 0.5F;
if (this.lidAngle < f3 && f2 >= f3 && this.adjacentChestZNeg == null && this.adjacentChestXNeg == null)
{
double d3 = (double)i + 0.5D;
double d0 = (double)k + 0.5D;
if (this.adjacentChestZPos != null)
{
d0 += 0.5D;
}
if (this.adjacentChestXPos != null)
{
d3 += 0.5D;
}
this.worldObj.playSound(SoundEvent.CHESTCLOSED, d3, (double)j + 0.5D, d0, 0.5F, this.worldObj.rand.floatv() * 0.1F + 0.9F);
}
if (this.lidAngle < 0.0F)
{
this.lidAngle = 0.0F;
}
}
}
public boolean receiveClientEvent(int id, int type)
{
if (id == 1)
{
this.numPlayersUsing = type;
return true;
}
else
{
return super.receiveClientEvent(id, type);
}
}
public void openInventory(EntityNPC player)
{
// if (!player.isSpectator())
// {
if (this.numPlayersUsing < 0)
{
this.numPlayersUsing = 0;
}
++this.numPlayersUsing;
this.worldObj.addBlockEvent(this.pos, this.getBlockType(), 1, this.numPlayersUsing);
this.worldObj.notifyNeighborsOfStateChange(this.pos, this.getBlockType());
this.worldObj.notifyNeighborsOfStateChange(this.pos.down(), this.getBlockType());
// }
}
public void closeInventory(EntityNPC player)
{
if (/* !player.isSpectator() && */ this.getBlockType() instanceof BlockChest)
{
--this.numPlayersUsing;
this.worldObj.addBlockEvent(this.pos, this.getBlockType(), 1, this.numPlayersUsing);
this.worldObj.notifyNeighborsOfStateChange(this.pos, this.getBlockType());
this.worldObj.notifyNeighborsOfStateChange(this.pos.down(), this.getBlockType());
}
}
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
*/
public boolean isItemValidForSlot(int index, ItemStack stack)
{
return true;
}
/**
* invalidates a tile entity
*/
public void invalidate()
{
super.invalidate();
this.updateContainingBlockInfo();
this.checkForAdjacentChests();
}
public int getChestType()
{
if (this.cachedChestType == -1)
{
if (this.worldObj == null || !(this.getBlockType() instanceof BlockChest))
{
return 0;
}
this.cachedChestType = ((BlockChest)this.getBlockType()).chestType;
}
return this.cachedChestType;
}
public String getGuiID()
{
return "chest";
}
public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn)
{
return new ContainerChest(playerInventory, this, playerIn);
}
public int getField(int id)
{
return 0;
}
public void setField(int id, int value)
{
}
public int getFieldCount()
{
return 0;
}
public void clear()
{
for (int i = 0; i < this.chestContents.length; ++i)
{
this.chestContents[i] = null;
}
}
public int getColor() {
return 0xffff00;
}
}

View file

@ -0,0 +1,34 @@
package game.tileentity;
import game.nbt.NBTTagCompound;
public class TileEntityComparator extends TileEntity
{
private int outputSignal;
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
compound.setInteger("OutputSignal", this.outputSignal);
}
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
this.outputSignal = compound.getInteger("OutputSignal");
}
public int getOutputSignal()
{
return this.outputSignal;
}
public void setOutputSignal(int p_145995_1_)
{
this.outputSignal = p_145995_1_;
}
public int getColor() {
return 0xaf0000;
}
}

View file

@ -0,0 +1,27 @@
package game.tileentity;
import game.block.BlockDaylightDetector;
import game.world.WorldServer;
public class TileEntityDaylightDetector extends TileEntity implements ITickable
{
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
if (this.worldObj != null && !this.worldObj.client && ((WorldServer)this.worldObj).getTime() % 20L == 0L)
{
this.blockType = this.getBlockType();
if (this.blockType instanceof BlockDaylightDetector)
{
((BlockDaylightDetector)this.blockType).updatePower((WorldServer)this.worldObj, this.pos);
}
}
}
public int getColor() {
return 0xffffaf;
}
}

View file

@ -0,0 +1,269 @@
package game.tileentity;
import game.entity.npc.EntityNPC;
import game.inventory.Container;
import game.inventory.ContainerDispenser;
import game.inventory.IInventory;
import game.inventory.InventoryPlayer;
import game.item.ItemStack;
import game.nbt.NBTTagCompound;
import game.nbt.NBTTagList;
import game.rng.Random;
public class TileEntityDispenser extends TileEntityLockable implements IInventory
{
private static final Random RNG = new Random();
private ItemStack[] stacks = new ItemStack[9];
protected String customName;
/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory()
{
return 9;
}
/**
* Returns the stack in the given slot.
*/
public ItemStack getStackInSlot(int index)
{
return this.stacks[index];
}
/**
* Removes up to a specified number of items from an inventory slot and returns them in a new stack.
*/
public ItemStack decrStackSize(int index, int count)
{
if (this.stacks[index] != null)
{
if (this.stacks[index].stackSize <= count)
{
ItemStack itemstack1 = this.stacks[index];
this.stacks[index] = null;
this.markDirty();
return itemstack1;
}
else
{
ItemStack itemstack = this.stacks[index].splitStack(count);
if (this.stacks[index].stackSize == 0)
{
this.stacks[index] = null;
}
this.markDirty();
return itemstack;
}
}
else
{
return null;
}
}
/**
* Removes a stack from the given slot and returns it.
*/
public ItemStack removeStackFromSlot(int index)
{
if (this.stacks[index] != null)
{
ItemStack itemstack = this.stacks[index];
this.stacks[index] = null;
return itemstack;
}
else
{
return null;
}
}
public int getDispenseSlot()
{
int i = -1;
int j = 1;
for (int k = 0; k < this.stacks.length; ++k)
{
if (this.stacks[k] != null && RNG.zrange(j++) == 0)
{
i = k;
}
}
return i;
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
*/
public void setInventorySlotContents(int index, ItemStack stack)
{
this.stacks[index] = stack;
if (stack != null && stack.stackSize > this.getInventoryStackLimit())
{
stack.stackSize = this.getInventoryStackLimit();
}
this.markDirty();
}
/**
* Add the given ItemStack to this Dispenser. Return the Slot the Item was placed in or -1 if no free slot is
* available.
*/
public int addItemStack(ItemStack stack)
{
for (int i = 0; i < this.stacks.length; ++i)
{
if (this.stacks[i] == null || this.stacks[i].getItem() == null)
{
this.setInventorySlotContents(i, stack);
return i;
}
}
return -1;
}
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
return this.hasCustomName() ? this.customName : "Werfer";
}
public void setCustomName(String customName)
{
this.customName = customName;
}
/**
* Returns true if this thing is named
*/
public boolean hasCustomName()
{
return this.customName != null;
}
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
NBTTagList nbttaglist = compound.getTagList("Items", 10);
this.stacks = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound.getByte("Slot") & 255;
if (j >= 0 && j < this.stacks.length)
{
this.stacks[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
}
}
if (compound.hasKey("CustomName", 8))
{
this.customName = compound.getString("CustomName");
}
}
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.stacks.length; ++i)
{
if (this.stacks[i] != null)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte)i);
this.stacks[i].writeToNBT(nbttagcompound);
nbttaglist.appendTag(nbttagcompound);
}
}
compound.setTag("Items", nbttaglist);
if (this.hasCustomName())
{
compound.setString("CustomName", this.customName);
}
}
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
public int getInventoryStackLimit()
{
return ItemStack.MAX_SIZE;
}
/**
* Do not make give this method the name canInteractWith because it clashes with Container
*/
public boolean isUseableByPlayer(EntityNPC player)
{
return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
}
public void openInventory(EntityNPC player)
{
}
public void closeInventory(EntityNPC player)
{
}
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
*/
public boolean isItemValidForSlot(int index, ItemStack stack)
{
return true;
}
public String getGuiID()
{
return "dispenser";
}
public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn)
{
return new ContainerDispenser(playerInventory, this);
}
public int getField(int id)
{
return 0;
}
public void setField(int id, int value)
{
}
public int getFieldCount()
{
return 0;
}
public void clear()
{
for (int i = 0; i < this.stacks.length; ++i)
{
this.stacks[i] = null;
}
}
public int getColor() {
return 0xffbf00;
}
}

View file

@ -0,0 +1,17 @@
package game.tileentity;
public class TileEntityDropper extends TileEntityDispenser
{
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
return this.hasCustomName() ? this.customName : "Spender";
}
public String getGuiID()
{
return "dropper";
}
}

View file

@ -0,0 +1,168 @@
package game.tileentity;
import game.ExtMath;
import game.entity.npc.EntityNPC;
import game.inventory.Container;
import game.inventory.ContainerEnchantment;
import game.inventory.InventoryPlayer;
import game.nbt.NBTTagCompound;
import game.rng.Random;
public class TileEntityEnchantmentTable extends TileEntity implements ITickable, IInteractionObject
{
public int tickCount;
public float pageFlip;
public float pageFlipPrev;
public float field_145932_k;
public float field_145929_l;
public float bookSpread;
public float bookSpreadPrev;
public float bookRotation;
public float bookRotationPrev;
public float field_145924_q;
private static Random rand = new Random();
private String customName;
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
if (this.hasCustomName())
{
compound.setString("CustomName", this.customName);
}
}
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
if (compound.hasKey("CustomName", 8))
{
this.customName = compound.getString("CustomName");
}
}
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
this.bookSpreadPrev = this.bookSpread;
this.bookRotationPrev = this.bookRotation;
EntityNPC entityplayer = this.worldObj.getClosestPlayer((double)((float)this.pos.getX() + 0.5F), (double)((float)this.pos.getY() + 0.5F), (double)((float)this.pos.getZ() + 0.5F), 3.0D);
if (entityplayer != null)
{
double d0 = entityplayer.posX - (double)((float)this.pos.getX() + 0.5F);
double d1 = entityplayer.posZ - (double)((float)this.pos.getZ() + 0.5F);
this.field_145924_q = (float)ExtMath.atan2(d1, d0);
this.bookSpread += 0.1F;
if (this.bookSpread < 0.5F || rand.zrange(40) == 0)
{
float f1 = this.field_145932_k;
while (true)
{
this.field_145932_k += (float)(rand.zrange(4) - rand.zrange(4));
if (f1 != this.field_145932_k)
{
break;
}
}
}
}
else
{
this.field_145924_q += 0.02F;
this.bookSpread -= 0.1F;
}
while (this.bookRotation >= (float)Math.PI)
{
this.bookRotation -= ((float)Math.PI * 2F);
}
while (this.bookRotation < -(float)Math.PI)
{
this.bookRotation += ((float)Math.PI * 2F);
}
while (this.field_145924_q >= (float)Math.PI)
{
this.field_145924_q -= ((float)Math.PI * 2F);
}
while (this.field_145924_q < -(float)Math.PI)
{
this.field_145924_q += ((float)Math.PI * 2F);
}
float f2;
for (f2 = this.field_145924_q - this.bookRotation; f2 >= (float)Math.PI; f2 -= ((float)Math.PI * 2F))
{
;
}
while (f2 < -(float)Math.PI)
{
f2 += ((float)Math.PI * 2F);
}
this.bookRotation += f2 * 0.4F;
this.bookSpread = ExtMath.clampf(this.bookSpread, 0.0F, 1.0F);
++this.tickCount;
this.pageFlipPrev = this.pageFlip;
float f = (this.field_145932_k - this.pageFlip) * 0.4F;
float f3 = 0.2F;
f = ExtMath.clampf(f, -f3, f3);
this.field_145929_l += (f - this.field_145929_l) * 0.9F;
this.pageFlip += this.field_145929_l;
}
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
return this.hasCustomName() ? this.customName : "Verzaubern";
}
/**
* Returns true if this thing is named
*/
public boolean hasCustomName()
{
return this.customName != null && this.customName.length() > 0;
}
public void setCustomName(String customNameIn)
{
this.customName = customNameIn;
}
/**
* Get the formatted ChatComponent that will be used for the sender's username in chat
*/
public String getCommandName()
{
return this.getName(); // (TextComponent)(this.hasCustomName() ? new TextComponent(this.getName()) : new TextComponent(this.getName()));
}
public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn)
{
return new ContainerEnchantment(playerInventory, this.worldObj, this.pos);
}
public String getGuiID()
{
return "enchanting_table";
}
public int getColor() {
return 0xbf00ff;
}
}

View file

@ -0,0 +1,537 @@
package game.tileentity;
import game.ExtMath;
import game.block.Block;
import game.block.BlockFurnace;
import game.block.BlockSapling;
import game.block.BlockSlab;
import game.entity.npc.EntityNPC;
import game.init.Blocks;
import game.init.Items;
import game.init.SmeltingRegistry;
import game.init.ToolType;
import game.inventory.Container;
import game.inventory.ContainerFurnace;
import game.inventory.IInventory;
import game.inventory.ISidedInventory;
import game.inventory.InventoryPlayer;
import game.inventory.SlotFurnaceFuel;
import game.item.Item;
import game.item.ItemBlock;
import game.item.ItemBucket;
import game.item.ItemHoe;
import game.item.ItemStack;
import game.item.ItemSword;
import game.item.ItemTool;
import game.material.Material;
import game.nbt.NBTTagCompound;
import game.nbt.NBTTagList;
import game.world.Facing;
public class TileEntityFurnace extends TileEntityLockable implements ITickable, ISidedInventory
{
private static final int[] slotsTop = new int[] {0};
private static final int[] slotsBottom = new int[] {2, 1};
private static final int[] slotsSides = new int[] {1};
/**
* The ItemStacks that hold the items currently being used in the furnace
*/
private ItemStack[] furnaceItemStacks = new ItemStack[3];
/** The number of ticks that the furnace will keep burning */
private int furnaceBurnTime;
/**
* The number of ticks that a fresh copy of the currently-burning item would keep the furnace burning for
*/
private int currentItemBurnTime;
private int cookTime;
private int totalCookTime;
private String furnaceCustomName;
/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory()
{
return this.furnaceItemStacks.length;
}
/**
* Returns the stack in the given slot.
*/
public ItemStack getStackInSlot(int index)
{
return this.furnaceItemStacks[index];
}
/**
* Removes up to a specified number of items from an inventory slot and returns them in a new stack.
*/
public ItemStack decrStackSize(int index, int count)
{
if (this.furnaceItemStacks[index] != null)
{
if (this.furnaceItemStacks[index].stackSize <= count)
{
ItemStack itemstack1 = this.furnaceItemStacks[index];
this.furnaceItemStacks[index] = null;
return itemstack1;
}
else
{
ItemStack itemstack = this.furnaceItemStacks[index].splitStack(count);
if (this.furnaceItemStacks[index].stackSize == 0)
{
this.furnaceItemStacks[index] = null;
}
return itemstack;
}
}
else
{
return null;
}
}
/**
* Removes a stack from the given slot and returns it.
*/
public ItemStack removeStackFromSlot(int index)
{
if (this.furnaceItemStacks[index] != null)
{
ItemStack itemstack = this.furnaceItemStacks[index];
this.furnaceItemStacks[index] = null;
return itemstack;
}
else
{
return null;
}
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
*/
public void setInventorySlotContents(int index, ItemStack stack)
{
boolean flag = stack != null && stack.isItemEqual(this.furnaceItemStacks[index]) && ItemStack.areItemStackTagsEqual(stack, this.furnaceItemStacks[index]);
this.furnaceItemStacks[index] = stack;
if (stack != null && stack.stackSize > this.getInventoryStackLimit())
{
stack.stackSize = this.getInventoryStackLimit();
}
if (index == 0 && !flag)
{
this.totalCookTime = this.getCookTime(stack);
this.cookTime = 0;
this.markDirty();
}
}
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
return this.hasCustomName() ? this.furnaceCustomName : "Ofen";
}
/**
* Returns true if this thing is named
*/
public boolean hasCustomName()
{
return this.furnaceCustomName != null && this.furnaceCustomName.length() > 0;
}
public void setCustomInventoryName(String p_145951_1_)
{
this.furnaceCustomName = p_145951_1_;
}
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
NBTTagList nbttaglist = compound.getTagList("Items", 10);
this.furnaceItemStacks = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound.getByte("Slot");
if (j >= 0 && j < this.furnaceItemStacks.length)
{
this.furnaceItemStacks[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
}
}
this.furnaceBurnTime = compound.getShort("BurnTime");
this.cookTime = compound.getShort("CookTime");
this.totalCookTime = compound.getShort("CookTimeTotal");
this.currentItemBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
if (compound.hasKey("CustomName", 8))
{
this.furnaceCustomName = compound.getString("CustomName");
}
}
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
compound.setShort("BurnTime", (short)this.furnaceBurnTime);
compound.setShort("CookTime", (short)this.cookTime);
compound.setShort("CookTimeTotal", (short)this.totalCookTime);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.furnaceItemStacks.length; ++i)
{
if (this.furnaceItemStacks[i] != null)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte)i);
this.furnaceItemStacks[i].writeToNBT(nbttagcompound);
nbttaglist.appendTag(nbttagcompound);
}
}
compound.setTag("Items", nbttaglist);
if (this.hasCustomName())
{
compound.setString("CustomName", this.furnaceCustomName);
}
}
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
public int getInventoryStackLimit()
{
return ItemStack.MAX_SIZE;
}
/**
* Furnace isBurning
*/
public boolean isBurning()
{
return this.furnaceBurnTime > 0;
}
public static boolean isBurning(IInventory p_174903_0_)
{
return p_174903_0_.getField(0) > 0;
}
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
boolean flag = this.isBurning();
boolean flag1 = false;
if (this.isBurning())
{
--this.furnaceBurnTime;
}
if (!this.worldObj.client)
{
if (this.isBurning() || this.furnaceItemStacks[1] != null && this.furnaceItemStacks[0] != null)
{
if (!this.isBurning() && this.canSmelt())
{
this.currentItemBurnTime = this.furnaceBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);
if (this.isBurning())
{
flag1 = true;
if (this.furnaceItemStacks[1] != null)
{
--this.furnaceItemStacks[1].stackSize;
if (this.furnaceItemStacks[1].stackSize == 0)
{
Item item = this.furnaceItemStacks[1].getItem().getContainerItem();
this.furnaceItemStacks[1] = item != null ? new ItemStack(item) : null;
}
}
}
}
if (this.isBurning() && this.canSmelt())
{
++this.cookTime;
if (this.cookTime == this.totalCookTime)
{
this.cookTime = 0;
this.totalCookTime = this.getCookTime(this.furnaceItemStacks[0]);
this.smeltItem();
flag1 = true;
}
}
else
{
this.cookTime = 0;
}
}
else if (!this.isBurning() && this.cookTime > 0)
{
this.cookTime = ExtMath.clampi(this.cookTime - 2, 0, this.totalCookTime);
}
if (flag != this.isBurning())
{
flag1 = true;
BlockFurnace.setState(this.isBurning(), this.worldObj, this.pos);
}
}
if (flag1)
{
this.markDirty();
}
}
public int getCookTime(ItemStack stack)
{
return 200;
}
/**
* Returns true if the furnace can smelt an item, i.e. has a source item, destination stack isn't full, etc.
*/
private boolean canSmelt()
{
if (this.furnaceItemStacks[0] == null)
{
return false;
}
else
{
ItemStack itemstack = SmeltingRegistry.getResult(this.furnaceItemStacks[0]);
return itemstack == null ? false : (this.furnaceItemStacks[2] == null ? true : (!this.furnaceItemStacks[2].isItemEqual(itemstack) ? false : (this.furnaceItemStacks[2].stackSize < this.getInventoryStackLimit() && this.furnaceItemStacks[2].stackSize < this.furnaceItemStacks[2].getMaxStackSize() ? true : this.furnaceItemStacks[2].stackSize < itemstack.getMaxStackSize())));
}
}
/**
* Turn one item from the furnace source stack into the appropriate smelted item in the furnace result stack
*/
public void smeltItem()
{
if (this.canSmelt())
{
ItemStack itemstack = SmeltingRegistry.getResult(this.furnaceItemStacks[0]);
if (this.furnaceItemStacks[2] == null)
{
this.furnaceItemStacks[2] = itemstack.copy();
}
else if (this.furnaceItemStacks[2].getItem() == itemstack.getItem())
{
++this.furnaceItemStacks[2].stackSize;
}
// if (this.furnaceItemStacks[0].getItem() == ItemRegistry.getItemFromBlock(Blocks.sponge) && this.furnaceItemStacks[0].getMetadata() == 1 && this.furnaceItemStacks[1] != null && this.furnaceItemStacks[1].getItem() == Items.bucket)
// {
// this.furnaceItemStacks[1] = new ItemStack(Items.water_bucket);
// }
--this.furnaceItemStacks[0].stackSize;
if (this.furnaceItemStacks[0].stackSize <= 0)
{
this.furnaceItemStacks[0] = null;
}
}
}
/**
* Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't
* fuel
*/
public static int getItemBurnTime(ItemStack p_145952_0_) // TODO: fuelreg!!
{
if (p_145952_0_ == null)
{
return 0;
}
else
{
Item item = p_145952_0_.getItem();
if (item instanceof ItemBlock && item.getBlock() != null) // Blocks.air)
{
Block block = item.getBlock();
// if (block instanceof BlockVerticalSlab && )
// {
// return 150;
// }
if (block.getMaterial() == Material.wood)
{
return block instanceof BlockSlab ? 150 : 300;
}
if (block == Blocks.coal_block)
{
return 16000;
}
}
return item instanceof ItemTool && ((ItemTool)item).getToolMaterial() == ToolType.WOOD.material ? 200 :
(item instanceof ItemSword && ((ItemSword)item).getToolMaterial() == ToolType.WOOD.material ? 200 :
(item instanceof ItemHoe && ((ItemHoe)item).getToolMaterial() == ToolType.WOOD.material ? 200 :
(item == Items.stick ? 100 :
(item == Items.coal ? 1600 :
(item instanceof ItemBucket && ((ItemBucket)item).getLiquid() != null &&
((ItemBucket)item).getLiquid().getMaterial() == Material.lava ? 20000 :
(item.getBlock() instanceof BlockSapling ? 100 :
(item == Items.blaze_rod ? 2400 : 0)))))));
}
}
public static boolean isItemFuel(ItemStack p_145954_0_)
{
return getItemBurnTime(p_145954_0_) > 0;
}
/**
* Do not make give this method the name canInteractWith because it clashes with Container
*/
public boolean isUseableByPlayer(EntityNPC player)
{
return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
}
public void openInventory(EntityNPC player)
{
}
public void closeInventory(EntityNPC player)
{
}
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
*/
public boolean isItemValidForSlot(int index, ItemStack stack)
{
return index == 2 ? false : (index != 1 ? true : isItemFuel(stack) || SlotFurnaceFuel.isBucket(stack));
}
public int[] getSlotsForFace(Facing side)
{
return side == Facing.DOWN ? slotsBottom : (side == Facing.UP ? slotsTop : slotsSides);
}
/**
* Returns true if automation can insert the given item in the given slot from the given side. Args: slot, item,
* side
*/
public boolean canInsertItem(int index, ItemStack itemStackIn, Facing direction)
{
return this.isItemValidForSlot(index, itemStackIn);
}
/**
* Returns true if automation can extract the given item in the given slot from the given side. Args: slot, item,
* side
*/
public boolean canExtractItem(int index, ItemStack stack, Facing direction)
{
if (direction == Facing.DOWN && index == 1)
{
Item item = stack.getItem();
if (/* item != Items.water_bucket && */ item != Items.bucket)
{
return false;
}
}
return true;
}
public String getGuiID()
{
return "furnace";
}
public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn)
{
return new ContainerFurnace(playerInventory, this);
}
public int getField(int id)
{
switch (id)
{
case 0:
return this.furnaceBurnTime;
case 1:
return this.currentItemBurnTime;
case 2:
return this.cookTime;
case 3:
return this.totalCookTime;
default:
return 0;
}
}
public void setField(int id, int value)
{
switch (id)
{
case 0:
this.furnaceBurnTime = value;
break;
case 1:
this.currentItemBurnTime = value;
break;
case 2:
this.cookTime = value;
break;
case 3:
this.totalCookTime = value;
}
}
public int getFieldCount()
{
return 4;
}
public void clear()
{
for (int i = 0; i < this.furnaceItemStacks.length; ++i)
{
this.furnaceItemStacks[i] = null;
}
}
public int getColor() {
return 0xff7f00;
}
}

View file

@ -0,0 +1,765 @@
package game.tileentity;
import java.util.List;
import java.util.function.Predicate;
import game.ExtMath;
import game.block.Block;
import game.block.BlockChest;
import game.block.BlockHopper;
import game.entity.Entity;
import game.entity.item.EntityItem;
import game.entity.npc.EntityNPC;
import game.init.Config;
import game.inventory.Container;
import game.inventory.ContainerHopper;
import game.inventory.IInventory;
import game.inventory.ISidedInventory;
import game.inventory.InventoryPlayer;
import game.item.ItemStack;
import game.nbt.NBTTagCompound;
import game.nbt.NBTTagList;
import game.world.BlockPos;
import game.world.BoundingBox;
import game.world.Facing;
import game.world.World;
public class TileEntityHopper extends TileEntityLockable implements IHopper, ITickable
{
private ItemStack[] inventory = new ItemStack[5];
private String customName;
private int transferCooldown = -1;
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
NBTTagList nbttaglist = compound.getTagList("Items", 10);
this.inventory = new ItemStack[this.getSizeInventory()];
if (compound.hasKey("CustomName", 8))
{
this.customName = compound.getString("CustomName");
}
this.transferCooldown = compound.getInteger("TransferCooldown");
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound.getByte("Slot");
if (j >= 0 && j < this.inventory.length)
{
this.inventory[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
}
}
}
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.inventory.length; ++i)
{
if (this.inventory[i] != null)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte)i);
this.inventory[i].writeToNBT(nbttagcompound);
nbttaglist.appendTag(nbttagcompound);
}
}
compound.setTag("Items", nbttaglist);
compound.setInteger("TransferCooldown", this.transferCooldown);
if (this.hasCustomName())
{
compound.setString("CustomName", this.customName);
}
}
/**
* For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it
* hasn't changed and skip it.
*/
public void markDirty()
{
super.markDirty();
}
/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory()
{
return this.inventory.length;
}
/**
* Returns the stack in the given slot.
*/
public ItemStack getStackInSlot(int index)
{
return this.inventory[index];
}
/**
* Removes up to a specified number of items from an inventory slot and returns them in a new stack.
*/
public ItemStack decrStackSize(int index, int count)
{
if (this.inventory[index] != null)
{
if (this.inventory[index].stackSize <= count)
{
ItemStack itemstack1 = this.inventory[index];
this.inventory[index] = null;
return itemstack1;
}
else
{
ItemStack itemstack = this.inventory[index].splitStack(count);
if (this.inventory[index].stackSize == 0)
{
this.inventory[index] = null;
}
return itemstack;
}
}
else
{
return null;
}
}
/**
* Removes a stack from the given slot and returns it.
*/
public ItemStack removeStackFromSlot(int index)
{
if (this.inventory[index] != null)
{
ItemStack itemstack = this.inventory[index];
this.inventory[index] = null;
return itemstack;
}
else
{
return null;
}
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
*/
public void setInventorySlotContents(int index, ItemStack stack)
{
this.inventory[index] = stack;
if (stack != null && stack.stackSize > this.getInventoryStackLimit())
{
stack.stackSize = this.getInventoryStackLimit();
}
}
/**
* Get the name of this object. For players this returns their username
*/
public String getName()
{
return this.hasCustomName() ? this.customName : "Trichter";
}
/**
* Returns true if this thing is named
*/
public boolean hasCustomName()
{
return this.customName != null && this.customName.length() > 0;
}
public void setCustomName(String customNameIn)
{
this.customName = customNameIn;
}
/**
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended.
*/
public int getInventoryStackLimit()
{
return ItemStack.MAX_SIZE;
}
/**
* Do not make give this method the name canInteractWith because it clashes with Container
*/
public boolean isUseableByPlayer(EntityNPC player)
{
return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
}
public void openInventory(EntityNPC player)
{
}
public void closeInventory(EntityNPC player)
{
}
/**
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
*/
public boolean isItemValidForSlot(int index, ItemStack stack)
{
return true;
}
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
if (this.worldObj != null && !this.worldObj.client)
{
--this.transferCooldown;
if (!this.isOnTransferCooldown())
{
this.setTransferCooldown(0);
this.updateHopper();
}
}
}
public boolean updateHopper()
{
if (this.worldObj != null && !this.worldObj.client)
{
if (!this.isOnTransferCooldown() && BlockHopper.isEnabled(this.getBlockMetadata()))
{
boolean flag = false;
if (!this.isEmpty())
{
flag = this.transferItemsOut();
}
if (!this.isFull())
{
flag = captureDroppedItems(this) || flag;
}
if (flag)
{
this.setTransferCooldown(Config.hopperDelay);
this.markDirty();
return true;
}
}
return false;
}
else
{
return false;
}
}
private boolean isEmpty()
{
for (ItemStack itemstack : this.inventory)
{
if (itemstack != null)
{
return false;
}
}
return true;
}
private boolean isFull()
{
for (ItemStack itemstack : this.inventory)
{
if (itemstack == null || itemstack.stackSize != itemstack.getMaxStackSize())
{
return false;
}
}
return true;
}
private boolean transferItemsOut()
{
IInventory iinventory = this.getInventoryForHopperTransfer();
if (iinventory == null)
{
return false;
}
else
{
Facing enumfacing = BlockHopper.getFacing(this.getBlockMetadata()).getOpposite();
if (isInventoryFull(iinventory, enumfacing))
{
return false;
}
else
{
for (int i = 0; i < this.getSizeInventory(); ++i)
{
if (this.getStackInSlot(i) != null)
{
ItemStack itemstack = this.getStackInSlot(i).copy();
ItemStack itemstack1 = putStackInInventoryAllSlots(iinventory, this.decrStackSize(i, 1), enumfacing);
if (itemstack1 == null || itemstack1.stackSize == 0)
{
iinventory.markDirty();
return true;
}
this.setInventorySlotContents(i, itemstack);
}
}
return false;
}
}
}
/**
* Returns false if the inventory has any room to place items in
*/
public static boolean isInventoryFull(IInventory inventoryIn, Facing side)
{
if (inventoryIn instanceof ISidedInventory)
{
ISidedInventory isidedinventory = (ISidedInventory)inventoryIn;
int[] aint = isidedinventory.getSlotsForFace(side);
for (int k = 0; k < aint.length; ++k)
{
ItemStack itemstack1 = isidedinventory.getStackInSlot(aint[k]);
if (itemstack1 == null || itemstack1.stackSize != itemstack1.getMaxStackSize())
{
return false;
}
}
}
else
{
int i = inventoryIn.getSizeInventory();
for (int j = 0; j < i; ++j)
{
ItemStack itemstack = inventoryIn.getStackInSlot(j);
if (itemstack == null || itemstack.stackSize != itemstack.getMaxStackSize())
{
return false;
}
}
}
return true;
}
/**
* Returns false if the specified IInventory contains any items
*/
public static boolean isInventoryEmpty(IInventory inventoryIn, Facing side)
{
if (inventoryIn instanceof ISidedInventory)
{
ISidedInventory isidedinventory = (ISidedInventory)inventoryIn;
int[] aint = isidedinventory.getSlotsForFace(side);
for (int i = 0; i < aint.length; ++i)
{
if (isidedinventory.getStackInSlot(aint[i]) != null)
{
return false;
}
}
}
else
{
int j = inventoryIn.getSizeInventory();
for (int k = 0; k < j; ++k)
{
if (inventoryIn.getStackInSlot(k) != null)
{
return false;
}
}
}
return true;
}
public static boolean captureDroppedItems(IHopper p_145891_0_)
{
IInventory iinventory = getHopperInventory(p_145891_0_);
if (iinventory != null)
{
Facing enumfacing = Facing.DOWN;
if (isInventoryEmpty(iinventory, enumfacing))
{
return false;
}
if (iinventory instanceof ISidedInventory)
{
ISidedInventory isidedinventory = (ISidedInventory)iinventory;
int[] aint = isidedinventory.getSlotsForFace(enumfacing);
for (int i = 0; i < aint.length; ++i)
{
if (pullItemFromSlot(p_145891_0_, iinventory, aint[i], enumfacing))
{
return true;
}
}
}
else
{
int j = iinventory.getSizeInventory();
for (int k = 0; k < j; ++k)
{
if (pullItemFromSlot(p_145891_0_, iinventory, k, enumfacing))
{
return true;
}
}
}
}
else
{
for (EntityItem entityitem : func_181556_a(p_145891_0_.getWorld(), p_145891_0_.getXPos(), p_145891_0_.getYPos() + 1.0D, p_145891_0_.getZPos()))
{
if (putDropInInventoryAllSlots(p_145891_0_, entityitem))
{
return true;
}
}
}
return false;
}
/**
* Pulls from the specified slot in the inventory and places in any available slot in the hopper. Returns true if
* the entire stack was moved
*/
public static boolean pullItemFromSlot(IHopper hopper, IInventory inventoryIn, int index, Facing direction)
{
ItemStack itemstack = inventoryIn.getStackInSlot(index);
if (itemstack != null && canExtractItemFromSlot(inventoryIn, itemstack, index, direction))
{
ItemStack itemstack1 = itemstack.copy();
ItemStack itemstack2 = putStackInInventoryAllSlots(hopper, inventoryIn.decrStackSize(index, 1), (Facing)null);
if (itemstack2 == null || itemstack2.stackSize == 0)
{
inventoryIn.markDirty();
return true;
}
inventoryIn.setInventorySlotContents(index, itemstack1);
}
return false;
}
/**
* Attempts to place the passed EntityItem's stack into the inventory using as many slots as possible. Returns false
* if the stackSize of the drop was not depleted.
*/
public static boolean putDropInInventoryAllSlots(IInventory p_145898_0_, EntityItem itemIn)
{
boolean flag = false;
if (itemIn == null)
{
return false;
}
else
{
ItemStack itemstack = itemIn.getEntityItem().copy();
ItemStack itemstack1 = putStackInInventoryAllSlots(p_145898_0_, itemstack, (Facing)null);
if (itemstack1 != null && itemstack1.stackSize != 0)
{
itemIn.setEntityItemStack(itemstack1);
}
else
{
flag = true;
itemIn.setDead();
}
return flag;
}
}
/**
* Attempts to place the passed stack in the inventory, using as many slots as required. Returns leftover items
*/
public static ItemStack putStackInInventoryAllSlots(IInventory inventoryIn, ItemStack stack, Facing side)
{
if (inventoryIn instanceof ISidedInventory && side != null)
{
ISidedInventory isidedinventory = (ISidedInventory)inventoryIn;
int[] aint = isidedinventory.getSlotsForFace(side);
for (int k = 0; k < aint.length && stack != null && stack.stackSize > 0; ++k)
{
stack = insertStack(inventoryIn, stack, aint[k], side);
}
}
else
{
int i = inventoryIn.getSizeInventory();
for (int j = 0; j < i && stack != null && stack.stackSize > 0; ++j)
{
stack = insertStack(inventoryIn, stack, j, side);
}
}
if (stack != null && stack.stackSize == 0)
{
stack = null;
}
return stack;
}
/**
* Can this hopper insert the specified item from the specified slot on the specified side?
*/
public static boolean canInsertItemInSlot(IInventory inventoryIn, ItemStack stack, int index, Facing side)
{
return !inventoryIn.isItemValidForSlot(index, stack) ? false : !(inventoryIn instanceof ISidedInventory) || ((ISidedInventory)inventoryIn).canInsertItem(index, stack, side);
}
/**
* Can this hopper extract the specified item from the specified slot on the specified side?
*/
public static boolean canExtractItemFromSlot(IInventory inventoryIn, ItemStack stack, int index, Facing side)
{
return !(inventoryIn instanceof ISidedInventory) || ((ISidedInventory)inventoryIn).canExtractItem(index, stack, side);
}
/**
* Insert the specified stack to the specified inventory and return any leftover items
*/
public static ItemStack insertStack(IInventory inventoryIn, ItemStack stack, int index, Facing side)
{
ItemStack itemstack = inventoryIn.getStackInSlot(index);
if (canInsertItemInSlot(inventoryIn, stack, index, side))
{
boolean flag = false;
if (itemstack == null)
{
inventoryIn.setInventorySlotContents(index, stack);
stack = null;
flag = true;
}
else if (canCombine(itemstack, stack))
{
int i = stack.getMaxStackSize() - itemstack.stackSize;
int j = Math.min(stack.stackSize, i);
stack.stackSize -= j;
itemstack.stackSize += j;
flag = j > 0;
}
if (flag)
{
if (inventoryIn instanceof TileEntityHopper)
{
TileEntityHopper tileentityhopper = (TileEntityHopper)inventoryIn;
if (tileentityhopper.mayTransfer())
{
tileentityhopper.setTransferCooldown(Config.hopperDelay);
}
inventoryIn.markDirty();
}
inventoryIn.markDirty();
}
}
return stack;
}
/**
* Returns the IInventory that this hopper is pointing into
*/
private IInventory getInventoryForHopperTransfer()
{
Facing enumfacing = BlockHopper.getFacing(this.getBlockMetadata());
return getInventoryAtPosition(this.getWorld(), (double)(this.pos.getX() + enumfacing.getFrontOffsetX()), (double)(this.pos.getY() + enumfacing.getFrontOffsetY()), (double)(this.pos.getZ() + enumfacing.getFrontOffsetZ()));
}
/**
* Returns the IInventory for the specified hopper
*/
public static IInventory getHopperInventory(IHopper hopper)
{
return getInventoryAtPosition(hopper.getWorld(), hopper.getXPos(), hopper.getYPos() + 1.0D, hopper.getZPos());
}
public static List<EntityItem> func_181556_a(World p_181556_0_, double p_181556_1_, double p_181556_3_, double p_181556_5_)
{
return p_181556_0_.<EntityItem>getEntitiesWithinAABB(EntityItem.class, new BoundingBox(p_181556_1_ - 0.5D, p_181556_3_ - 0.5D, p_181556_5_ - 0.5D, p_181556_1_ + 0.5D, p_181556_3_ + 0.5D, p_181556_5_ + 0.5D), new Predicate<EntityItem>() {
public boolean test(EntityItem entity) {
return entity.isEntityAlive();
}
});
}
/**
* Returns the IInventory (if applicable) of the TileEntity at the specified position
*/
public static IInventory getInventoryAtPosition(World worldIn, double x, double y, double z)
{
IInventory iinventory = null;
int i = ExtMath.floord(x);
int j = ExtMath.floord(y);
int k = ExtMath.floord(z);
BlockPos blockpos = new BlockPos(i, j, k);
Block block = worldIn.getState(blockpos).getBlock();
if (block.hasTileEntity())
{
TileEntity tileentity = worldIn.getTileEntity(blockpos);
if (tileentity instanceof IInventory)
{
iinventory = (IInventory)tileentity;
if (iinventory instanceof TileEntityChest && block instanceof BlockChest)
{
iinventory = ((BlockChest)block).getLockableContainer(worldIn, blockpos);
}
}
}
if (iinventory == null)
{
List<Entity> list = worldIn.getEntitiesInAABBexcluding((Entity)null, new BoundingBox(x - 0.5D, y - 0.5D, z - 0.5D, x + 0.5D, y + 0.5D, z + 0.5D), new Predicate<Entity>() {
public boolean test(Entity entity) {
return entity instanceof IInventory && entity.isEntityAlive();
}
});
if (list.size() > 0)
{
iinventory = (IInventory)list.get(worldIn.rand.zrange(list.size()));
}
}
return iinventory;
}
public static boolean canCombine(ItemStack stack1, ItemStack stack2)
{
return stack1.getItem() != stack2.getItem() ? false : (stack1.getMetadata() != stack2.getMetadata() ? false : (stack1.stackSize > stack1.getMaxStackSize() ? false : ItemStack.areItemStackTagsEqual(stack1, stack2)));
}
/**
* Gets the world X position for this hopper entity.
*/
public double getXPos()
{
return (double)this.pos.getX() + 0.5D;
}
/**
* Gets the world Y position for this hopper entity.
*/
public double getYPos()
{
return (double)this.pos.getY() + 0.5D;
}
/**
* Gets the world Z position for this hopper entity.
*/
public double getZPos()
{
return (double)this.pos.getZ() + 0.5D;
}
public void setTransferCooldown(int ticks)
{
this.transferCooldown = ticks;
}
public boolean isOnTransferCooldown()
{
return this.transferCooldown > 0;
}
public boolean mayTransfer()
{
return this.transferCooldown <= 1;
}
public String getGuiID()
{
return "hopper";
}
public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn)
{
return new ContainerHopper(playerInventory, this, playerIn);
}
public int getField(int id)
{
return 0;
}
public void setField(int id, int value)
{
}
public int getFieldCount()
{
return 0;
}
public void clear()
{
for (int i = 0; i < this.inventory.length; ++i)
{
this.inventory[i] = null;
}
}
public int getColor() {
return 0x0040ff;
}
}

View file

@ -0,0 +1,50 @@
package game.tileentity;
import game.nbt.NBTTagCompound;
public abstract class TileEntityLockable extends TileEntity implements IInteractionObject, ILockableContainer
{
private LockCode code = LockCode.EMPTY_CODE;
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
this.code = LockCode.fromNBT(compound);
}
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
if (this.code != null)
{
this.code.toNBT(compound);
}
}
public boolean isLocked()
{
return this.code != null && !this.code.isEmpty();
}
public LockCode getLockCode()
{
return this.code;
}
public void setLockCode(LockCode code)
{
this.code = code;
}
public abstract String getName();
public abstract boolean hasCustomName();
/**
* Get the formatted ChatComponent that will be used for the sender's username in chat
*/
public String getCommandName()
{
return this.getName(); // (TextComponent)(this.hasCustomName() ? new TextComponent(this.getName()) : new TextComponent(this.getName()));
}
}

View file

@ -0,0 +1,337 @@
package game.tileentity;
import game.ExtMath;
import game.color.TextColor;
import game.entity.npc.EntityNPC;
import game.inventory.Container;
import game.inventory.ContainerMachine;
import game.inventory.InventoryPlayer;
import game.item.ItemStack;
import game.nbt.NBTTagCompound;
import game.nbt.NBTTagList;
import game.network.Packet;
import game.packet.S35PacketUpdateTileEntity;
import game.rng.Random;
public abstract class TileEntityMachine extends TileEntityLockable implements IHopper, ITickable {
public static enum Status {
OFF(TextColor.DGRAY, "Inaktiv"),
COOLING(TextColor.YELLOW, "Abkühlen ..."),
RUNNING(TextColor.GREEN, "Aktiv"),
OVERHEAT(TextColor.RED, "Überhitzt!"),
BROKEN(TextColor.BLACK, "Defekt!");
public final TextColor color;
public final String name;
private Status(TextColor color, String name) {
this.color = color;
this.name = name;
}
}
protected final ItemStack[] inventory;
protected final MachineResource[] resources;
protected final Random rand = new Random();
// protected boolean isCreative;
protected int temperature;
protected Status status = Status.OFF;
protected TileEntityMachine(int slots, MachineResource ... resources) {
this.inventory = new ItemStack[slots];
this.resources = resources;
}
protected abstract int getTempIncrement();
protected abstract int getTempDecrement();
protected abstract int getMaxTemp();
protected abstract boolean executeFunction();
public MachineResource getResource(int slot) {
return this.resources[slot];
}
// public void setCreative(boolean creative) {
// this.isCreative = creative;
// }
//
// public boolean isCreative() {
// return this.isCreative;
// }
public int getNumResources() {
return this.resources.length;
}
public int getTemperature() {
return this.temperature;
}
public void setTemperature(int temp) {
this.temperature = temp;
}
public Status getStatus() {
return this.status;
}
public void setStatus(Status status) {
this.status = status;
}
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
NBTTagList nbttaglist = compound.getTagList("Items", 10);
this.clear();
for(int i = 0; i < nbttaglist.tagCount(); ++i) {
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound.getByte("Slot");
if(j >= 0 && j < this.inventory.length) {
this.inventory[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
}
}
nbttaglist = compound.getTagList("Resources", 10);
for(MachineResource res : this.resources) {
res.reset();
}
for(int i = 0; i < nbttaglist.tagCount() && i < this.inventory.length; ++i) {
this.resources[i].readFromNbt(nbttaglist.getCompoundTagAt(i));
}
// this.isCreative = compound.getBoolean("Creative");
this.temperature = compound.getInteger("Temperature");
this.status = Status.values()[(int)compound.getByte("Status") % Status.values().length];
}
public void writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
NBTTagList nbttaglist = new NBTTagList();
for(int i = 0; i < this.inventory.length; ++i) {
if(this.inventory[i] != null) {
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte)i);
this.inventory[i].writeToNBT(nbttagcompound);
nbttaglist.appendTag(nbttagcompound);
}
}
compound.setTag("Items", nbttaglist);
nbttaglist = new NBTTagList();
for(int z = 0; z < this.resources.length; z++) {
NBTTagCompound res = new NBTTagCompound();
this.resources[z].writeToNbt(res);
nbttaglist.appendTag(res);
}
compound.setTag("Resources", nbttaglist);
// compound.setBoolean("Creative", this.isCreative);
compound.setInteger("Temperature", this.temperature);
compound.setByte("Status", (byte)this.status.ordinal());
}
// public void markDirty()
// {
// super.markDirty();
// }
public int getSizeInventory() {
return this.inventory.length;
}
public ItemStack getStackInSlot(int index) {
return this.inventory[index];
}
public ItemStack decrStackSize(int index, int count) {
if(this.inventory[index] != null) {
if(this.inventory[index].stackSize <= count) {
ItemStack itemstack1 = this.inventory[index];
this.inventory[index] = null;
return itemstack1;
}
else {
ItemStack itemstack = this.inventory[index].splitStack(count);
if(this.inventory[index].stackSize == 0) {
this.inventory[index] = null;
}
return itemstack;
}
}
else {
return null;
}
}
public ItemStack removeStackFromSlot(int index) {
if(this.inventory[index] != null) {
ItemStack itemstack = this.inventory[index];
this.inventory[index] = null;
return itemstack;
}
else {
return null;
}
}
public void setInventorySlotContents(int index, ItemStack stack) {
this.inventory[index] = stack;
if(stack != null && stack.stackSize > this.getInventoryStackLimit()) {
stack.stackSize = this.getInventoryStackLimit();
}
}
public boolean hasCustomName() {
return false;
}
public int getInventoryStackLimit() {
return ItemStack.MAX_SIZE;
}
public boolean isUseableByPlayer(EntityNPC player) {
return this.worldObj.getTileEntity(this.pos) != this ? false
: player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
}
public void openInventory(EntityNPC player) {
}
public void closeInventory(EntityNPC player) {
}
public boolean isItemValidForSlot(int index, ItemStack stack) {
return true;
}
public void detonate() {
this.worldObj.newExplosion(null, this.getXPos(), this.getYPos(), this.getZPos(), 5.0f, true, true, false);
}
public void update() {
if(this.worldObj != null && !this.worldObj.client && this.status != Status.BROKEN) {
int envTemp = (int)this.worldObj.getTemperatureC(this.getPos());
if(this.executeFunction()) {
this.temperature += this.getTempIncrement();
this.status = this.temperature >= (this.getMaxTemp() * 9) / 10 ? Status.OVERHEAT : Status.RUNNING;
if(this.temperature > this.getMaxTemp()) {
this.status = Status.BROKEN;
this.markDirty();
this.detonate();
return;
}
else {
this.markDirty();
}
}
else {
int dec = this.getTempDecrement();
if(dec != 0) {
int prev = this.temperature;
this.temperature -= dec;
this.temperature = ExtMath.clampi(this.temperature, envTemp, Integer.MAX_VALUE);
if(prev != this.temperature)
this.markDirty();
else
dec = 0;
}
Status prev = this.status;
this.status = this.temperature >= (this.getMaxTemp() * 9) / 10 ? Status.OVERHEAT :
(this.temperature == envTemp ? Status.OFF : Status.COOLING);
if(dec == 0 && prev != this.status) {
this.markDirty();
}
}
if(this.temperature < envTemp) {
this.temperature = envTemp;
this.markDirty();
}
}
}
public boolean isEmpty(int slot) {
if(slot == -1) {
for(ItemStack itemstack : this.inventory) {
if(itemstack != null)
return false;
}
return true;
}
else {
return this.inventory[slot] == null || this.inventory[slot].stackSize <= 0;
}
}
public boolean hasAmount(int slot, int amount) {
if(slot == -1) {
int n = 0;
for(ItemStack itemstack : this.inventory) {
if(itemstack != null && itemstack.stackSize >= 1)
n += itemstack.stackSize;
}
return n >= amount;
}
else {
return this.inventory[slot] != null && this.inventory[slot].stackSize >= amount;
}
}
public boolean isFull() {
for(ItemStack itemstack : this.inventory) {
if(itemstack == null || itemstack.stackSize != itemstack.getMaxStackSize()) {
return false;
}
}
return true;
}
public double getXPos() {
return (double)this.pos.getX() + 0.5D;
}
public double getYPos() {
return (double)this.pos.getY() + 0.5D;
}
public double getZPos() {
return (double)this.pos.getZ() + 0.5D;
}
public Container createContainer(InventoryPlayer playerInventory, EntityNPC playerIn) {
return new ContainerMachine(playerInventory, this, this, playerIn);
}
public int getField(int id) {
return 0;
}
public void setField(int id, int value) {
}
public int getFieldCount() {
return 0;
}
public void clear() {
for(int i = 0; i < this.inventory.length; ++i) {
this.inventory[i] = null;
}
}
public Packet getDescriptionPacket()
{
return new S35PacketUpdateTileEntity(this);
}
public int getColor() {
return 0x8080ff;
}
public abstract String formatDisplay();
}

View file

@ -0,0 +1,243 @@
package game.tileentity;
import game.entity.Entity;
import game.entity.types.EntityLiving;
import game.init.Blocks;
import game.init.Config;
import game.init.EntityRegistry;
import game.nbt.NBTTagCompound;
import game.network.Packet;
import game.packet.S35PacketUpdateTileEntity;
import game.renderer.particle.ParticleType;
import game.world.BlockPos;
import game.world.BoundingBox;
import game.world.World;
public class TileEntityMobSpawner extends TileEntity implements ITickable
{
private int spawnDelay = 20;
private String mobID = "Pig";
private double mobRotation;
private double prevMobRotation;
private int minSpawnDelay = 200;
private int maxSpawnDelay = 800;
private int spawnCount = 4;
private Entity cachedEntity;
private int maxNearbyEntities = 6;
private int activatingRangeFromPlayer = 16;
private int spawnRange = 4;
public Packet getDescriptionPacket()
{
return new S35PacketUpdateTileEntity(this);
}
public boolean receiveClientEvent(int id, int type)
{
if (id == 1 && this.worldObj.client)
{
this.spawnDelay = this.minSpawnDelay;
return true;
}
else
{
return super.receiveClientEvent(id, type);
}
}
// public boolean hasSpecialNBT()
// {
// return true;
// }
public int getColor() {
return 0xff0000;
}
public void update()
{
BlockPos blockpos = this.pos;
if (this.worldObj.isAnyPlayerWithinRangeAt((double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D, (double)this.activatingRangeFromPlayer))
{
if (this.worldObj.client)
{
double d3 = (double)((float)blockpos.getX() + this.worldObj.rand.floatv());
double d4 = (double)((float)blockpos.getY() + this.worldObj.rand.floatv());
double d5 = (double)((float)blockpos.getZ() + this.worldObj.rand.floatv());
this.worldObj.spawnParticle(ParticleType.SMOKE_NORMAL, d3, d4, d5, 0.0D, 0.0D, 0.0D);
this.worldObj.spawnParticle(ParticleType.FLAME, d3, d4, d5, 0.0D, 0.0D, 0.0D);
if (this.spawnDelay > 0)
{
--this.spawnDelay;
}
this.prevMobRotation = this.mobRotation;
this.mobRotation = (this.mobRotation + (double)(1000.0F / ((float)this.spawnDelay + 200.0F))) % 360.0D;
}
else
{
if(!Config.mobs || !Config.spawners) {
return;
}
if (this.spawnDelay == -1)
{
this.resetTimer();
}
if (this.spawnDelay > 0)
{
--this.spawnDelay;
return;
}
boolean flag = false;
for (int i = 0; i < this.spawnCount; ++i)
{
Entity entity = EntityRegistry.createEntityByName(this.mobID, this.worldObj);
if (entity == null)
{
return;
}
int j = this.worldObj.getEntitiesWithinAABB(entity.getClass(), (new BoundingBox((double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ(), (double)(blockpos.getX() + 1), (double)(blockpos.getY() + 1), (double)(blockpos.getZ() + 1))).expand((double)this.spawnRange, (double)this.spawnRange, (double)this.spawnRange)).size();
if (j >= this.maxNearbyEntities)
{
this.resetTimer();
return;
}
double d0 = (double)blockpos.getX() + (this.worldObj.rand.doublev() - this.worldObj.rand.doublev()) * (double)this.spawnRange + 0.5D;
double d1 = (double)(blockpos.getY() + this.worldObj.rand.zrange(3) - 1);
double d2 = (double)blockpos.getZ() + (this.worldObj.rand.doublev() - this.worldObj.rand.doublev()) * (double)this.spawnRange + 0.5D;
EntityLiving entityliving = entity instanceof EntityLiving ? (EntityLiving)entity : null;
entity.setLocationAndAngles(d0, d1, d2, this.worldObj.rand.floatv() * 360.0F, 0.0F);
if (entityliving == null || entityliving.getCanSpawnHere() && entityliving.isNotColliding())
{
if (entity instanceof EntityLiving && entity.worldObj != null)
{
// if (entity instanceof EntityLiving)
// {
((EntityLiving)entity).onInitialSpawn(null);
// }
entity.worldObj.spawnEntityInWorld(entity);
}
this.worldObj.playAuxSFX(2004, blockpos, 0);
if (entityliving != null)
{
entityliving.spawnExplosionParticle();
}
flag = true;
}
}
if (flag)
{
this.resetTimer();
}
}
}
}
private void resetTimer()
{
if (this.maxSpawnDelay <= this.minSpawnDelay)
{
this.spawnDelay = this.minSpawnDelay;
}
else
{
int i = this.maxSpawnDelay - this.minSpawnDelay;
this.spawnDelay = this.minSpawnDelay + this.worldObj.rand.zrange(i);
}
this.worldObj.addBlockEvent(TileEntityMobSpawner.this.pos, Blocks.mob_spawner, 1, 0);
}
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.mobID = nbt.getString("EntityId");
this.spawnDelay = nbt.getShort("Delay");
if (nbt.hasKey("MinSpawnDelay", 99))
{
this.minSpawnDelay = nbt.getShort("MinSpawnDelay");
this.maxSpawnDelay = nbt.getShort("MaxSpawnDelay");
this.spawnCount = nbt.getShort("SpawnCount");
}
if (nbt.hasKey("MaxNearbyEntities", 99))
{
this.maxNearbyEntities = nbt.getShort("MaxNearbyEntities");
this.activatingRangeFromPlayer = nbt.getShort("RequiredPlayerRange");
}
if (nbt.hasKey("SpawnRange", 99))
{
this.spawnRange = nbt.getShort("SpawnRange");
}
if (this.worldObj != null)
{
this.cachedEntity = null;
}
}
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
String s = this.mobID;
if (s != null && !s.isEmpty())
{
nbt.setString("EntityId", s);
nbt.setShort("Delay", (short)this.spawnDelay);
nbt.setShort("MinSpawnDelay", (short)this.minSpawnDelay);
nbt.setShort("MaxSpawnDelay", (short)this.maxSpawnDelay);
nbt.setShort("SpawnCount", (short)this.spawnCount);
nbt.setShort("MaxNearbyEntities", (short)this.maxNearbyEntities);
nbt.setShort("RequiredPlayerRange", (short)this.activatingRangeFromPlayer);
nbt.setShort("SpawnRange", (short)this.spawnRange);
}
}
public Entity createRenderEntity(World worldIn)
{
if (this.cachedEntity == null)
{
this.cachedEntity = EntityRegistry.createEntityByName(this.mobID, worldIn);
// if (entity != null)
// {
//// entity = this.spawnNewEntity(entity, false);
// this.cachedEntity = entity;
// }
}
return this.cachedEntity;
}
public double getMobRotation()
{
return this.mobRotation;
}
public double getPrevMobRotation()
{
return this.prevMobRotation;
}
public void setEntityName(String name)
{
this.mobID = name;
}
}

View file

@ -0,0 +1,74 @@
package game.tileentity;
import game.ExtMath;
import game.init.Blocks;
import game.material.Material;
import game.nbt.NBTTagCompound;
import game.world.BlockPos;
import game.world.World;
public class TileEntityNote extends TileEntity
{
/** Note to play */
public byte note;
/** stores the latest redstone state */
public boolean previousRedstoneState;
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
compound.setByte("note", this.note);
}
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
this.note = compound.getByte("note");
this.note = (byte)ExtMath.clampi(this.note, 0, 24);
}
/**
* change pitch by -> (currentPitch + 1) % 25
*/
public void changePitch()
{
this.note = (byte)((this.note + 1) % 25);
this.markDirty();
}
public void triggerNote(World worldIn, BlockPos p_175108_2_)
{
if (worldIn.getState(p_175108_2_.up()).getBlock().getMaterial() == Material.air)
{
// Material material = worldIn.getBlockState(p_175108_2_.down()).getBlock().getMaterial();
// int i = 0;
//
// if (material == Material.rock)
// {
// i = 1;
// }
//
// if (material == Material.sand)
// {
// i = 2;
// }
//
// if (material == Material.glass)
// {
// i = 3;
// }
//
// if (material == Material.wood)
// {
// i = 4;
// }
worldIn.addBlockEvent(p_175108_2_, Blocks.noteblock, 0, this.note);
}
}
public int getColor() {
return 0x80ff00;
}
}

View file

@ -0,0 +1,223 @@
package game.tileentity;
import java.util.List;
import game.collect.Lists;
import game.entity.Entity;
import game.init.BlockRegistry;
import game.init.Blocks;
import game.nbt.NBTTagCompound;
import game.world.BoundingBox;
import game.world.Facing;
import game.world.State;
public class TileEntityPiston extends TileEntity implements ITickable
{
private State pistonState;
private Facing pistonFacing;
/** if this piston is extending or not */
private boolean extending;
private boolean shouldHeadBeRendered;
private float progress;
/** the progress in (de)extending */
private float lastProgress;
private List<Entity> field_174933_k = Lists.<Entity>newArrayList();
public TileEntityPiston()
{
}
public TileEntityPiston(State pistonStateIn, Facing pistonFacingIn, boolean extendingIn, boolean shouldHeadBeRenderedIn)
{
this.pistonState = pistonStateIn;
this.pistonFacing = pistonFacingIn;
this.extending = extendingIn;
this.shouldHeadBeRendered = shouldHeadBeRenderedIn;
}
public State getPistonState()
{
return this.pistonState;
}
public int getBlockMetadata()
{
return 0;
}
/**
* Returns true if a piston is extending
*/
public boolean isExtending()
{
return this.extending;
}
public Facing getFacing()
{
return this.pistonFacing;
}
public boolean shouldPistonHeadBeRendered()
{
return this.shouldHeadBeRendered;
}
/**
* Get interpolated progress value (between lastProgress and progress) given the fractional time between ticks as an
* argument
*/
public float getProgress(float ticks)
{
if (ticks > 1.0F)
{
ticks = 1.0F;
}
return this.lastProgress + (this.progress - this.lastProgress) * ticks;
}
public float getOffsetX(float ticks)
{
return this.extending ? (this.getProgress(ticks) - 1.0F) * (float)this.pistonFacing.getFrontOffsetX() : (1.0F - this.getProgress(ticks)) * (float)this.pistonFacing.getFrontOffsetX();
}
public float getOffsetY(float ticks)
{
return this.extending ? (this.getProgress(ticks) - 1.0F) * (float)this.pistonFacing.getFrontOffsetY() : (1.0F - this.getProgress(ticks)) * (float)this.pistonFacing.getFrontOffsetY();
}
public float getOffsetZ(float ticks)
{
return this.extending ? (this.getProgress(ticks) - 1.0F) * (float)this.pistonFacing.getFrontOffsetZ() : (1.0F - this.getProgress(ticks)) * (float)this.pistonFacing.getFrontOffsetZ();
}
private void launchWithSlimeBlock(float p_145863_1_, float p_145863_2_)
{
if (this.extending)
{
p_145863_1_ = 1.0F - p_145863_1_;
}
else
{
--p_145863_1_;
}
BoundingBox axisalignedbb = Blocks.piston_extension.getBoundingBox(this.worldObj, this.pos, this.pistonState, p_145863_1_, this.pistonFacing);
if (axisalignedbb != null)
{
List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity((Entity)null, axisalignedbb);
if (!list.isEmpty())
{
this.field_174933_k.addAll(list);
for (Entity entity : this.field_174933_k)
{
if (this.pistonState.getBlock() == Blocks.slime_block && this.extending)
{
switch (this.pistonFacing.getAxis())
{
case X:
entity.motionX = (double)this.pistonFacing.getFrontOffsetX();
break;
case Y:
entity.motionY = (double)this.pistonFacing.getFrontOffsetY();
break;
case Z:
entity.motionZ = (double)this.pistonFacing.getFrontOffsetZ();
}
}
else
{
entity.moveEntity((double)(p_145863_2_ * (float)this.pistonFacing.getFrontOffsetX()), (double)(p_145863_2_ * (float)this.pistonFacing.getFrontOffsetY()), (double)(p_145863_2_ * (float)this.pistonFacing.getFrontOffsetZ()));
}
}
this.field_174933_k.clear();
}
}
}
/**
* removes a piston's tile entity (and if the piston is moving, stops it)
*/
public void clearPistonTileEntity()
{
if (this.lastProgress < 1.0F && this.worldObj != null)
{
this.lastProgress = this.progress = 1.0F;
this.worldObj.removeTileEntity(this.pos);
this.invalidate();
if (this.worldObj.getState(this.pos).getBlock() == Blocks.piston_extension)
{
this.worldObj.setState(this.pos, this.pistonState, 3);
this.worldObj.notifyBlockOfStateChange(this.pos, this.pistonState.getBlock());
}
}
}
/**
* Like the old updateEntity(), except more generic.
*/
public void update()
{
this.lastProgress = this.progress;
if (this.lastProgress >= 1.0F)
{
this.launchWithSlimeBlock(1.0F, 0.25F);
this.worldObj.removeTileEntity(this.pos);
this.invalidate();
if (this.worldObj.getState(this.pos).getBlock() == Blocks.piston_extension)
{
this.worldObj.setState(this.pos, this.pistonState, 3);
this.worldObj.notifyBlockOfStateChange(this.pos, this.pistonState.getBlock());
}
}
else
{
this.progress += 0.5F;
if (this.progress >= 1.0F)
{
this.progress = 1.0F;
}
if (this.extending)
{
this.launchWithSlimeBlock(this.progress, this.progress - this.lastProgress + 0.0625F);
}
}
}
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
this.pistonState = BlockRegistry.getBlockById(compound.getInteger("blockId")).getStateFromMeta(compound.getInteger("blockData"));
this.pistonFacing = Facing.getFront(compound.getInteger("facing"));
this.lastProgress = this.progress = compound.getFloat("progress");
this.extending = compound.getBoolean("extending");
}
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
compound.setInteger("blockId", BlockRegistry.getIdFromBlock(this.pistonState.getBlock()));
compound.setInteger("blockData", this.pistonState.getBlock().getMetaFromState(this.pistonState));
compound.setInteger("facing", this.pistonFacing.getIndex());
compound.setFloat("progress", this.lastProgress);
compound.setBoolean("extending", this.extending);
}
public int getColor() {
return 0x7f7f7f;
}
}

View file

@ -0,0 +1,131 @@
package game.tileentity;
import game.entity.npc.EntityNPC;
import game.nbt.NBTTagCompound;
import game.network.Packet;
import game.packet.S33PacketUpdateSign;
public class TileEntitySign extends TileEntity {
public final String[] signText = new String[] {"", "", "", ""};
/**
* The index of the line currently being edited. Only used on client side, but
* defined on both. Note this is only really used when the > < are going to be
* visible.
*/
// public int lineBeingEdited = -1;
// public String command;
// private boolean isEditable = true;
private EntityNPC player;
// private boolean oldFormat;
public void writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
for(int i = 0; i < 4; ++i) {
compound.setString("Text" + (i + 1), this.signText[i]);
}
// if(this.command != null)
// compound.setString("Command", this.command);
}
public void readFromNBT(NBTTagCompound compound) {
// this.isEditable = false;
super.readFromNBT(compound);
for(int i = 0; i < 4; ++i) {
this.signText[i] = compound.getString("Text" + (i + 1));
}
// if(compound.hasKey("Command", 8))
// this.command = compound.getString("Command");
// if(!compound.getBoolean("NewFormat")) {
// Log.debug("Konvertiere Schild bei " + this.pos.getX() + "," + this.pos.getY() + "," + this.pos.getZ() + " ...");
// byte newComp = 0;
// byte quotes = 0;
// String[] old = new String[4];
// for(int i = 0; i < 4; ++i) {
// old[i] = this.signText[i];
//// if(ChatFormat.hasLegacy(this.signText[i])) {
// this.signText[i] = ChatFormat.replaceLegacy(this.signText[i]);
//// }
// if(this.signText[i].startsWith("{") && this.signText[i].endsWith("}")) {
// try {
// TextComponent comp = TextSerializer.toComponent(this.signText[i]);
// this.signText[i] = comp.getFormattedText();
// newComp++;
// }
// catch(Throwable e) {
// }
// }
// else if(this.signText[i].startsWith("\"") && this.signText[i].endsWith("\"")) {
// newComp++;
// quotes |= 1 << i;
// }
// }
// for(int i = 0; i < 4; ++i) {
// if(newComp == 4 && (quotes & (1 << i)) != 0) {
// this.signText[i] = this.signText[i].substring(1, this.signText[i].length() - 1);
// }
// if(old[i] != this.signText[i]) {
// Log.debug("Zeile " + (i + 1) + ": '" + ChatFormat.stripCodes(this.signText[i]) + "'");
// }
// }
// this.oldFormat = true;
// }
}
// public boolean validate() {
// super.validate();
// if(this.oldFormat) {
// this.oldFormat = false;
// return true;
// }
// return false;
// }
/**
* Allows for a specialized description packet to be created. This is often used
* to sync tile entity data from the server to the client easily. For example
* this is used by signs to synchronise the text to be displayed.
*/
public Packet getDescriptionPacket() {
String[] aichatcomponent = new String[4];
System.arraycopy(this.signText, 0, aichatcomponent, 0, 4);
// Sign sign = Server.getServer().getSigns().getEntry(new WorldPos(this).toString());
return new S33PacketUpdateSign(this.worldObj, this.pos, aichatcomponent);
}
// public boolean hasSpecialNBT() {
// return true;
// }
// public boolean getIsEditable() {
// return this.isEditable;
// }
//
// /**
// * Sets the sign's isEditable flag to the specified parameter.
// */
// public void setEditable(boolean isEditableIn) {
// this.isEditable = isEditableIn;
//
// if(!isEditableIn) {
// this.player = null;
// }
// }
public void setPlayer(EntityNPC playerIn) {
this.player = playerIn;
}
public EntityNPC getPlayer() {
return this.player;
}
public int getColor() {
return 0x00ffff;
}
}

View file

@ -0,0 +1,61 @@
package game.tileentity;
import game.nbt.NBTTagCompound;
import game.network.Packet;
import game.packet.S35PacketUpdateTileEntity;
public class TileEntitySkull extends TileEntity
{
private int skullRotation;
// private String user = null;
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
compound.setByte("Rot", (byte)(this.skullRotation & 255));
// if(this.user != null)
// compound.setString("Owner", this.user);
}
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
this.skullRotation = compound.getByte("Rot");
// if(compound.hasKey("Owner", 8))
// this.user = compound.getString("Owner");
}
// public String getUser()
// {
// return this.user;
// }
/**
* Allows for a specialized description packet to be created. This is often used to sync tile entity data from the
* server to the client easily. For example this is used by signs to synchronise the text to be displayed.
*/
public Packet getDescriptionPacket()
{
return new S35PacketUpdateTileEntity(this);
}
// public void setUser(String user)
// {
// this.user = user;
// this.markDirty();
// }
public int getSkullRotation()
{
return this.skullRotation;
}
public void setSkullRotation(int rotation)
{
this.skullRotation = rotation;
}
public int getColor() {
return 0x00ff00;
}
}

View file

@ -0,0 +1,59 @@
package game.tileentity;
import game.init.Blocks;
import game.init.ItemRegistry;
import game.init.Items;
import game.item.ItemStack;
import game.tileentity.MachineResource.Type;
public class TileEntityTianReactor extends TileEntityMachine {
public TileEntityTianReactor() {
super(2, new MachineResource(Type.OUTPUT, "output.energy", 1024, 0, 0));
}
protected boolean executeFunction() {
if(!this.hasAmount(0, 2)) // && !this.isCreative)
return false;
if(this.rand.rarity(5))
return true;
// if(!this.isCreative) {
this.decrStackSize(0, 2);
this.decrStackSize(1, 1);
// }
this.getResource(0).add(this.rand.range(this.temperature / 200, this.temperature / 50), 20, false);
return true;
}
protected int getTempIncrement() {
return this.isEmpty(1) ? this.rand.range(20, 50) : (this.temperature >= this.rand.range(4200, 4250) ? 0 : this.rand.range(10, 15));
}
protected int getTempDecrement() {
return this.isEmpty(1) ? this.rand.chance(0, 1, 3) : this.rand.range(1, 3);
}
public boolean isItemValidForSlot(int index, ItemStack stack) {
return index == 0 ? stack.getItem() == Items.aluminium_ingot : (index == 1 ? stack.getItem() == ItemRegistry.getItemFromBlock(Blocks.lead_block) : false);
}
protected int getMaxTemp() {
return 8200;
}
public String getName() {
return "Tianreaktor";
}
public String getGuiID() {
return "tian_reactor";
}
public String formatDisplay() {
return String.format("Gespeicherte Energie: %d TF", this.getResource(0).getValue());
}
public void detonate() {
this.worldObj.setBlockToAir(getPos());
this.worldObj.newExplosion(this.getXPos(), this.getYPos(), this.getZPos(), 120);
}
}