initial commit
This commit is contained in:
parent
3c9ee26b06
commit
22186c33b9
1458 changed files with 282792 additions and 0 deletions
201
java/src/game/item/CheatTab.java
Executable file
201
java/src/game/item/CheatTab.java
Executable file
|
@ -0,0 +1,201 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.enchantment.EnumEnchantmentType;
|
||||
import game.init.Blocks;
|
||||
import game.init.ItemRegistry;
|
||||
import game.init.Items;
|
||||
|
||||
public abstract class CheatTab
|
||||
{
|
||||
public static final CheatTab[] TABS = new CheatTab[16];
|
||||
public static final CheatTab tabBlocks = new CheatTab("Baumaterial")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return ItemRegistry.getItemFromBlock(Blocks.glass);
|
||||
}
|
||||
};
|
||||
public static final CheatTab tabNature = new CheatTab("Gestein und Natur")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return ItemRegistry.getItemFromBlock(Blocks.grass);
|
||||
}
|
||||
};
|
||||
public static final CheatTab tabWood = new CheatTab("Holz")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return ItemRegistry.getItemFromBlock(Blocks.maple_planks);
|
||||
}
|
||||
};
|
||||
public static final CheatTab tabPlants = new CheatTab("Pflanzen")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return ItemRegistry.getItemFromBlock(Blocks.oak_leaves);
|
||||
}
|
||||
};
|
||||
public static final CheatTab tabDeco = new CheatTab("Dekoration")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return ItemRegistry.getItemFromBlock(Blocks.hay_block);
|
||||
}
|
||||
};
|
||||
public static final CheatTab tabTech = new CheatTab("Redstone & Technik")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return ItemRegistry.getItemFromBlock(Blocks.tnt);
|
||||
}
|
||||
};
|
||||
public static final CheatTab tabGems = new CheatTab("Erze & Teure Blöcke")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return ItemRegistry.getItemFromBlock(Blocks.diamond_block);
|
||||
}
|
||||
};
|
||||
public static final CheatTab tabInventory = new CheatTab("Inventar öffnen")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return ItemRegistry.getItemFromBlock(Blocks.chest);
|
||||
}
|
||||
};
|
||||
public static final CheatTab tabSpawners = new CheatTab("Mob & Itemspawner")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return Items.minecart;
|
||||
}
|
||||
};
|
||||
public static final CheatTab tabTools = new CheatTab("Werkzeug")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return Items.flint_and_steel;
|
||||
}
|
||||
};
|
||||
public static final CheatTab tabCombat = new CheatTab("Kampf")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return Items.bow;
|
||||
}
|
||||
};
|
||||
public static final CheatTab tabMagic = new CheatTab("Tränke & Verzauberungen")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return Items.potion;
|
||||
}
|
||||
public int getIconItemDamage()
|
||||
{
|
||||
return 8261;
|
||||
}
|
||||
};
|
||||
public static final CheatTab tabMaterials = new CheatTab("Werkstoffe")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return Items.leather;
|
||||
}
|
||||
};
|
||||
public static final CheatTab tabMetals = new CheatTab("Metalle und Juwelen")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return Items.iron_ingot;
|
||||
}
|
||||
};
|
||||
public static final CheatTab tabMisc = new CheatTab("Verschiedenes & Nahrung")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return Items.charge_crystal;
|
||||
}
|
||||
};
|
||||
public static final CheatTab tabEtc = new CheatTab("...")
|
||||
{
|
||||
public Item getTabIconItem()
|
||||
{
|
||||
return Items.navigator;
|
||||
}
|
||||
};
|
||||
|
||||
private static int nextTabId;
|
||||
|
||||
private final int tabIndex;
|
||||
private final String name;
|
||||
private EnumEnchantmentType[] enchantmentTypes;
|
||||
private ItemStack iconItemStack;
|
||||
|
||||
public CheatTab(String name)
|
||||
{
|
||||
this.tabIndex = nextTabId++;
|
||||
this.name = name;
|
||||
TABS[this.tabIndex] = this;
|
||||
}
|
||||
|
||||
public boolean isRight()
|
||||
{
|
||||
return this.getTabColumn() == (TABS.length + 1) / 2 - 1;
|
||||
}
|
||||
|
||||
public boolean isLeft()
|
||||
{
|
||||
return this.getTabColumn() == 0;
|
||||
}
|
||||
|
||||
public int getTabColumn()
|
||||
{
|
||||
return this.tabIndex % ((TABS.length + 1) / 2);
|
||||
}
|
||||
|
||||
public boolean isTop()
|
||||
{
|
||||
return this.tabIndex < (TABS.length + 1) / 2;
|
||||
}
|
||||
|
||||
public int getIndex()
|
||||
{
|
||||
return this.tabIndex;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public ItemStack getIconItemStack()
|
||||
{
|
||||
if (this.iconItemStack == null)
|
||||
{
|
||||
this.iconItemStack = new ItemStack(this.getTabIconItem(), 1, this.getIconItemDamage());
|
||||
}
|
||||
|
||||
return this.iconItemStack;
|
||||
}
|
||||
|
||||
public abstract Item getTabIconItem();
|
||||
|
||||
public int getIconItemDamage()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void displayAllReleventItems(List<ItemStack> list)
|
||||
{
|
||||
for (Item item : ItemRegistry.REGISTRY)
|
||||
{
|
||||
if (item != null && item.getTab() == this)
|
||||
{
|
||||
item.getSubItems(item, this, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
669
java/src/game/item/Item.java
Executable file
669
java/src/game/item/Item.java
Executable file
|
@ -0,0 +1,669 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import game.ExtMath;
|
||||
import game.block.Block;
|
||||
import game.collect.Maps;
|
||||
import game.collect.Sets;
|
||||
import game.color.TextColor;
|
||||
import game.entity.attributes.Attribute;
|
||||
import game.entity.attributes.AttributeModifier;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.renderer.ItemMeshDefinition;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.rng.Random;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.HitPosition;
|
||||
import game.world.Vec3;
|
||||
import game.world.World;
|
||||
|
||||
public class Item
|
||||
{
|
||||
protected static final Random itemRand = new Random();
|
||||
|
||||
protected int maxStackSize = 64;
|
||||
private int maxDamage;
|
||||
protected boolean hasSubtypes;
|
||||
private Item containerItem;
|
||||
private String potionEffect;
|
||||
private String display;
|
||||
private CheatTab tabToDisplayOn;
|
||||
private TextColor color = null;
|
||||
|
||||
public Item setMaxStackSize(int maxStackSize)
|
||||
{
|
||||
this.maxStackSize = maxStackSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Item setHasSubtypes(boolean hasSubtypes)
|
||||
{
|
||||
this.hasSubtypes = hasSubtypes;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* set max damage of an Item
|
||||
*/
|
||||
public Item setMaxDamage(int maxDamageIn)
|
||||
{
|
||||
this.maxDamage = maxDamageIn;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Item setDisplay(String name)
|
||||
{
|
||||
this.display = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Item setContainerItem(Item containerItem)
|
||||
{
|
||||
this.containerItem = containerItem;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the string representing this item's effect on a potion when used as an ingredient.
|
||||
*/
|
||||
public Item setPotionEffect(String potionEffect)
|
||||
{
|
||||
this.potionEffect = potionEffect;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns this;
|
||||
*/
|
||||
public Item setTab(CheatTab tab)
|
||||
{
|
||||
this.tabToDisplayOn = tab;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Item setColor(TextColor color)
|
||||
{
|
||||
this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Block getBlock()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an ItemStack with NBT data is read to potentially that ItemStack's NBT data
|
||||
*/
|
||||
public boolean updateItemStackNBT(NBTTagCompound nbt)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onAction(ItemStack stack, EntityNPC player, World world, ItemControl control, BlockPos block) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public float getStrVsBlock(ItemStack stack, Block state)
|
||||
{
|
||||
return 1.0F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
|
||||
* the Item before the action is complete.
|
||||
*/
|
||||
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum size of the stack for a specific item. *Isn't this more a Set than a Get?*
|
||||
*/
|
||||
public int getItemStackLimit()
|
||||
{
|
||||
return this.maxStackSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean getHasSubtypes()
|
||||
{
|
||||
return this.hasSubtypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum damage an item can take.
|
||||
*/
|
||||
public int getMaxDamage()
|
||||
{
|
||||
return this.maxDamage;
|
||||
}
|
||||
|
||||
public boolean isDamageable()
|
||||
{
|
||||
return this.maxDamage > 0 && !this.hasSubtypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
|
||||
* the damage on the stack.
|
||||
*/
|
||||
public boolean hitEntity(ItemStack stack, EntityLiving target, EntityLiving attacker)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
|
||||
*/
|
||||
public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLiving playerIn)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this Item can harvest the given Block
|
||||
*/
|
||||
public boolean canHarvestBlock(Block blockIn)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the item can be used on the given entity, e.g. shears on sheep.
|
||||
*/
|
||||
public boolean itemInteractionForEntity(ItemStack stack, EntityNPC playerIn, EntityLiving target)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// public String getUnlocalizedNameInefficiently(ItemStack stack)
|
||||
// {
|
||||
// String s = this.getUnlocalizedName(stack);
|
||||
// return s == null ? "" : s; // I18n.translate(s);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Returns the unlocalized name of this item.
|
||||
// */
|
||||
// public String getUnlocalizedName()
|
||||
// {
|
||||
// return "item." + this.unlocalizedName;
|
||||
// }
|
||||
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
return this.display;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this function returns true (or the item is damageable), the ItemStack's NBT tag will be sent to the client.
|
||||
*/
|
||||
public boolean getShareTag()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public Item getContainerItem()
|
||||
{
|
||||
return this.containerItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if this Item has a container item (a.k.a. crafting result)
|
||||
*/
|
||||
public boolean hasContainerItem()
|
||||
{
|
||||
return this.containerItem != null;
|
||||
}
|
||||
|
||||
public int getColorFromItemStack(ItemStack stack, int renderPass)
|
||||
{
|
||||
return 16777215;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Called each tick as long the item is on a player inventory. Uses by maps to check if is on a player hand and
|
||||
// * update it's contents.
|
||||
// */
|
||||
// public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Called when item is crafted/smelted. Used only by maps so far.
|
||||
// */
|
||||
// public void onCreated(ItemStack stack, World worldIn, EntityNPC playerIn)
|
||||
// {
|
||||
// }
|
||||
|
||||
/**
|
||||
* returns the action that specifies what animation to play when the items is being used
|
||||
*/
|
||||
public ItemAction getItemUseAction(ItemStack stack)
|
||||
{
|
||||
return ItemAction.NONE;
|
||||
}
|
||||
|
||||
public ItemAction getItemPosition(ItemStack stack)
|
||||
{
|
||||
return ItemAction.NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long it takes to use or consume an item
|
||||
*/
|
||||
public int getMaxItemUseDuration(ItemStack stack)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player stops using an Item (stops holding the right mouse button).
|
||||
*/
|
||||
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityNPC playerIn, int timeLeft)
|
||||
{
|
||||
}
|
||||
|
||||
public String getPotionEffect(ItemStack stack)
|
||||
{
|
||||
return this.potionEffect;
|
||||
}
|
||||
|
||||
public boolean isPotionIngredient(ItemStack stack)
|
||||
{
|
||||
return this.getPotionEffect(stack) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip)
|
||||
{
|
||||
}
|
||||
|
||||
// public String getItemStackDisplayName(ItemStack stack)
|
||||
// {
|
||||
// return this.getUnlocalizedName(stack);
|
||||
// }
|
||||
|
||||
public boolean hasEffect(ItemStack stack)
|
||||
{
|
||||
return stack.isItemEnchanted();
|
||||
}
|
||||
|
||||
public TextColor getColor(ItemStack stack)
|
||||
{
|
||||
return this.color != null ? this.color : (stack.isItemEnchanted() ? TextColor.NEON : TextColor.WHITE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks isDamagable and if it cannot be stacked
|
||||
*/
|
||||
public boolean isItemTool(ItemStack stack)
|
||||
{
|
||||
return this.getItemStackLimit() == 1 && this.isDamageable();
|
||||
}
|
||||
|
||||
protected HitPosition getMovingObjectPositionFromPlayer(World worldIn, EntityNPC playerIn, boolean useLiquids)
|
||||
{
|
||||
float f = playerIn.rotPitch;
|
||||
float f1 = playerIn.rotYaw;
|
||||
double d0 = playerIn.posX;
|
||||
double d1 = playerIn.posY + (double)playerIn.getEyeHeight();
|
||||
double d2 = playerIn.posZ;
|
||||
Vec3 vec3 = new Vec3(d0, d1, d2);
|
||||
float f2 = ExtMath.cos(-f1 * 0.017453292F - (float)Math.PI);
|
||||
float f3 = ExtMath.sin(-f1 * 0.017453292F - (float)Math.PI);
|
||||
float f4 = -ExtMath.cos(-f * 0.017453292F);
|
||||
float f5 = ExtMath.sin(-f * 0.017453292F);
|
||||
float f6 = f3 * f4;
|
||||
float f7 = f2 * f4;
|
||||
double d3 = 5.0D;
|
||||
Vec3 vec31 = vec3.addVector((double)f6 * d3, (double)f5 * d3, (double)f7 * d3);
|
||||
return worldIn.rayTraceBlocks(vec3, vec31, useLiquids, !useLiquids, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enchantability factor of the item, most of the time is based on material.
|
||||
*/
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(Item itemIn, CheatTab tab, List<ItemStack> subItems)
|
||||
{
|
||||
subItems.add(new ItemStack(itemIn, 1, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the tab this item is displayed on
|
||||
*/
|
||||
public CheatTab getTab()
|
||||
{
|
||||
return this.tabToDisplayOn;
|
||||
}
|
||||
|
||||
// public boolean canItemEditBlocks()
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Return whether this item is repairable in an anvil.
|
||||
*/
|
||||
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public Map<Attribute, Set<AttributeModifier>> getItemAttributeModifiers()
|
||||
{
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
|
||||
public Map<Attribute, Set<AttributeModifier>> getItemInventoryModifiers()
|
||||
{
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
|
||||
// public boolean canBeDyed() {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
public boolean isFragile() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// public boolean isValidMeta(int meta) {
|
||||
// return true; // meta == 0;
|
||||
// }
|
||||
//
|
||||
// public int getDefaultMeta() {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
public final Set<String> getValidTags() {
|
||||
return Sets.newHashSet();
|
||||
}
|
||||
|
||||
// private static final Set<String> VALID_TAGS = Sets.newHashSet("Name", "ench", "RepairCost");
|
||||
|
||||
protected final boolean validateNbt(NBTTagCompound tag) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// private final boolean isValidNbt(ItemStack stack) {
|
||||
// if(!stack.hasTagCompound()) {
|
||||
// return true;
|
||||
// }
|
||||
// NBTTagCompound tag = stack.getTagCompound();
|
||||
// if(tag.hasNoTags()) {
|
||||
// return false;
|
||||
// }
|
||||
// Set<String> keys = tag.getKeySet();
|
||||
// int z = keys.size();
|
||||
// boolean validate = false;
|
||||
// if(z > 0) {
|
||||
// for(String v : VALID_TAGS) {
|
||||
// if(keys.contains(v)) {
|
||||
// z--;
|
||||
// if(z == 0) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//// if(adv && z > 0) {
|
||||
////// for(String v : ADV_TAGS) {
|
||||
//// if(keys.contains("Unbreakable")) {
|
||||
//// z--;
|
||||
////// if(z == 0) {
|
||||
////// break;
|
||||
////// }
|
||||
//// }
|
||||
////// }
|
||||
//// }
|
||||
// if(z > 0) {
|
||||
// for(String v : this.getValidTags()) {
|
||||
// if(keys.contains(v)) {
|
||||
// validate = true;
|
||||
// z--;
|
||||
// if(z == 0) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if(z > 0) {
|
||||
// return false;
|
||||
// }
|
||||
//// if(tag.hasKey("display")) {
|
||||
//// if(!tag.hasKey("display", 10)) {
|
||||
//// return false;
|
||||
//// }
|
||||
//// NBTTagCompound display = tag.getCompoundTag("display");
|
||||
//// keys = display.getKeySet();
|
||||
//// z = keys.size();
|
||||
// if(tag.hasKey("Name")) {
|
||||
// if(!tag.hasKey("Name", 8)) {
|
||||
// return false;
|
||||
// }
|
||||
// if(tag.getString("Name").length() > 64) {
|
||||
// return false;
|
||||
// }
|
||||
//// z--;
|
||||
// }
|
||||
//// if(display.hasKey("Lore")) {
|
||||
//// if(!adv) {
|
||||
//// display.removeTag("Lore");
|
||||
//// if(display.hasNoTags()) {
|
||||
//// tag.removeTag("display");
|
||||
//// if(tag.hasNoTags()) {
|
||||
//// stack.setTagCompound(null);
|
||||
//// return true;
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
//// else {
|
||||
//// if(!display.hasKey("Lore", 9)) {
|
||||
//// return false;
|
||||
//// }
|
||||
//// NBTTagList lore = display.getTagList("Lore", 8);
|
||||
//// if(lore.hasNoTags()) {
|
||||
//// return false;
|
||||
//// }
|
||||
//// }
|
||||
//// z--;
|
||||
//// }
|
||||
//// if(display.hasKey("color")) {
|
||||
//// if(!display.hasKey("color", 3)) {
|
||||
//// return false;
|
||||
//// }
|
||||
//// if(!this.canBeDyed()) {
|
||||
//// return false;
|
||||
//// }
|
||||
//// z--;
|
||||
//// }
|
||||
//// if(z > 0) {
|
||||
//// return false;
|
||||
//// }
|
||||
//// }
|
||||
// if(tag.hasKey("RepairCost")) {
|
||||
// if(!tag.hasKey("RepairCost", 3)) {
|
||||
// return false;
|
||||
// }
|
||||
// if(tag.getInteger("RepairCost") < 1) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// if(tag.hasKey("ench")) {
|
||||
// if(!tag.hasKey("ench", 9)) {
|
||||
// return false;
|
||||
// }
|
||||
// NBTTagList ench = tag.getTagList("ench", 10);
|
||||
// if(ench.hasNoTags()) {
|
||||
// return false;
|
||||
// }
|
||||
// if(ench.tagCount() > Enchantment.getNames().size()) {
|
||||
// return false;
|
||||
// }
|
||||
// Enchantment[] ecn = new Enchantment[ench.tagCount()];
|
||||
// for(int e = 0; e < ench.tagCount(); e++) {
|
||||
// NBTTagCompound ec = ench.getCompoundTagAt(e);
|
||||
// if(ec.getKeySet().size() != 2 || !ec.hasKey("id", 2) || !ec.hasKey("lvl", 2)) {
|
||||
// return false;
|
||||
// }
|
||||
// int id = ec.getShort("id");
|
||||
// int lvl = ec.getShort("lvl");
|
||||
// Enchantment en = Enchantment.getEnchantmentById(id);
|
||||
// if(en == null) {
|
||||
// return false;
|
||||
// }
|
||||
//// if(!adv && (lvl < en.getMinLevel() || lvl > en.getMaxLevel())) {
|
||||
//// return false;
|
||||
//// }
|
||||
//// if(!adv && !en.canApply(stack)) {
|
||||
//// return false;
|
||||
//// }
|
||||
// ecn[e] = en;
|
||||
// }
|
||||
// for(int e = 0; e < ecn.length; e++) {
|
||||
// for(int f = 0; f < ecn.length; f++) {
|
||||
// if(f != e && ecn[e] == ecn[f]) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//// if(adv) {
|
||||
//// if(tag.hasKey("Unbreakable")) {
|
||||
//// if(!tag.hasKey("Unbreakable", 1)) {
|
||||
//// return false;
|
||||
//// }
|
||||
//// }
|
||||
//// if(tag.hasKey("HideFlags")) {
|
||||
//// if(!tag.hasKey("HideFlags", 3)) {
|
||||
//// return false;
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
// if(validate) {
|
||||
// if(this.validateNbt(stack.getTagCompound())) {
|
||||
// if(tag.hasNoTags()) {
|
||||
// stack.setTagCompound(null);
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// boolean validate(ItemStack stack) {
|
||||
//// if(!bypass && this.isSpecialItem()) {
|
||||
//// return false;
|
||||
//// }
|
||||
// boolean flag = true;
|
||||
// if(this.isDamageable() && (stack.getItemDamage() < 0 || (stack.getItemDamage() > this.getMaxDamage()))) {
|
||||
// stack.setItemDamage(0);
|
||||
// flag = false;
|
||||
// }
|
||||
// if(stack.stackSize > stack.getMaxStackSize()) {
|
||||
// stack.stackSize = stack.getMaxStackSize();
|
||||
// flag = false;
|
||||
// }
|
||||
// else if(stack.stackSize < 1) {
|
||||
// stack.stackSize = 1;
|
||||
// flag = false;
|
||||
// }
|
||||
// if(!this.isValidNbt(stack)) {
|
||||
// stack.setTagCompound(null);
|
||||
// flag = false;
|
||||
// }
|
||||
// return flag;
|
||||
// }
|
||||
|
||||
// public boolean canBreakBlocks() {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// public boolean canUseInAir() {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// public boolean ignoresBlocks() {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
public float getRadiation(ItemStack stack) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isFirstPerson() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getHotbarText(EntityNPC player, ItemStack stack) {
|
||||
return stack.getColoredName();
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.ITEM;
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(this.getTransform(), name);
|
||||
}
|
||||
|
||||
public ItemMeshDefinition getMesher() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
|
||||
this.getSubItems(itemIn, null, subItems);
|
||||
}
|
||||
}
|
5
java/src/game/item/ItemAction.java
Executable file
5
java/src/game/item/ItemAction.java
Executable file
|
@ -0,0 +1,5 @@
|
|||
package game.item;
|
||||
|
||||
public enum ItemAction {
|
||||
NONE, EAT, DRINK, BLOCK, AIM;
|
||||
}
|
21
java/src/game/item/ItemAmmo.java
Executable file
21
java/src/game/item/ItemAmmo.java
Executable file
|
@ -0,0 +1,21 @@
|
|||
package game.item;
|
||||
|
||||
public class ItemAmmo extends ItemMagnetic {
|
||||
private final int damage;
|
||||
private final float explosion;
|
||||
|
||||
public ItemAmmo(int damage, float explosion, int stack) {
|
||||
this.maxStackSize = stack;
|
||||
this.setTab(CheatTab.tabCombat);
|
||||
this.damage = damage;
|
||||
this.explosion = explosion;
|
||||
}
|
||||
|
||||
public int getDamage(ItemStack stack) {
|
||||
return this.damage;
|
||||
}
|
||||
|
||||
public float getExplosion() {
|
||||
return this.explosion;
|
||||
}
|
||||
}
|
24
java/src/game/item/ItemAnvilBlock.java
Executable file
24
java/src/game/item/ItemAnvilBlock.java
Executable file
|
@ -0,0 +1,24 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
|
||||
public class ItemAnvilBlock extends ItemMultiTexture
|
||||
{
|
||||
public ItemAnvilBlock(Block block)
|
||||
{
|
||||
super(block, block, new String[] {"Amboss", "Leicht beschädigter Amboss", "Stark beschädigter Amboss"});
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage << 2;
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return true;
|
||||
}
|
||||
}
|
63
java/src/game/item/ItemAppleGold.java
Executable file
63
java/src/game/item/ItemAppleGold.java
Executable file
|
@ -0,0 +1,63 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.potion.Potion;
|
||||
import game.potion.PotionEffect;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemAppleGold extends ItemFood
|
||||
{
|
||||
public ItemAppleGold(int amount, boolean isWolfFood)
|
||||
{
|
||||
super(amount, isWolfFood);
|
||||
this.setHasSubtypes(true);
|
||||
this.setColor(TextColor.NEON);
|
||||
}
|
||||
|
||||
public boolean hasEffect(ItemStack stack)
|
||||
{
|
||||
return stack.getMetadata() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an item rarity from EnumRarity
|
||||
*/
|
||||
public TextColor getColor(ItemStack stack)
|
||||
{
|
||||
return stack.getMetadata() == 0 ? super.getColor(stack) : TextColor.MAGENTA;
|
||||
}
|
||||
|
||||
protected void onFoodEaten(ItemStack stack, World worldIn, EntityNPC player)
|
||||
{
|
||||
if (!worldIn.client)
|
||||
{
|
||||
player.addEffect(new PotionEffect(Potion.absorption.id, 2400, 0));
|
||||
}
|
||||
|
||||
if (stack.getMetadata() > 0)
|
||||
{
|
||||
if (!worldIn.client)
|
||||
{
|
||||
player.addEffect(new PotionEffect(Potion.regeneration.id, 600, 4));
|
||||
player.addEffect(new PotionEffect(Potion.resistance.id, 6000, 0));
|
||||
player.addEffect(new PotionEffect(Potion.fireResistance.id, 6000, 0));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
super.onFoodEaten(stack, worldIn, player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(Item itemIn, CheatTab tab, List<ItemStack> subItems)
|
||||
{
|
||||
subItems.add(new ItemStack(itemIn, 1, 0));
|
||||
subItems.add(new ItemStack(itemIn, 1, 1));
|
||||
}
|
||||
}
|
325
java/src/game/item/ItemArmor.java
Executable file
325
java/src/game/item/ItemArmor.java
Executable file
|
@ -0,0 +1,325 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import game.block.BlockDispenser;
|
||||
import game.collect.Sets;
|
||||
import game.dispenser.BehaviorDefaultDispenseItem;
|
||||
import game.dispenser.IBehaviorDispenseItem;
|
||||
import game.dispenser.IBlockSource;
|
||||
import game.entity.attributes.Attribute;
|
||||
import game.entity.attributes.AttributeModifier;
|
||||
import game.entity.attributes.Attributes;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.init.DispenserRegistry;
|
||||
import game.init.ToolMaterial;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.world.BlockPos;
|
||||
import game.world.BoundingBox;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemArmor extends Item
|
||||
{
|
||||
// public static final String[] EMPTY_SLOT_NAMES = new String[] {"items/empty_armor_slot_helmet", "items/empty_armor_slot_chestplate", "items/empty_armor_slot_leggings", "items/empty_armor_slot_boots"};
|
||||
private static final IBehaviorDispenseItem dispenserBehavior = new BehaviorDefaultDispenseItem()
|
||||
{
|
||||
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
BlockPos blockpos = source.getBlockPos().offset(BlockDispenser.getFacing(source.getBlockMetadata()));
|
||||
int i = blockpos.getX();
|
||||
int j = blockpos.getY();
|
||||
int k = blockpos.getZ();
|
||||
BoundingBox axisalignedbb = new BoundingBox((double)i, (double)j, (double)k, (double)(i + 1), (double)(j + 1), (double)(k + 1));
|
||||
List<EntityLiving> list = source.getWorld().<EntityLiving>getEntitiesWithinAABB(EntityLiving.class, axisalignedbb, new Predicate<EntityLiving>() {
|
||||
public boolean test(EntityLiving entity) {
|
||||
return entity.isEntityAlive() && entity instanceof EntityNPC &&
|
||||
entity.getItem(ItemArmor.getArmorPosition(stack)) != null; // || entitylivingbase.isPlayer());
|
||||
}
|
||||
});
|
||||
|
||||
if (list.size() > 0)
|
||||
{
|
||||
EntityLiving entitylivingbase = (EntityLiving)list.get(0);
|
||||
int l = entitylivingbase.isPlayer() ? 1 : 0;
|
||||
int i1 = ItemArmor.getArmorPosition(stack);
|
||||
ItemStack itemstack = stack.copy();
|
||||
itemstack.stackSize = 1;
|
||||
entitylivingbase.setItem(i1 - l, itemstack);
|
||||
|
||||
// if (entitylivingbase instanceof EntityLiving)
|
||||
// {
|
||||
// ((EntityLiving)entitylivingbase).setDropChance(i1, 2.0F);
|
||||
// }
|
||||
|
||||
--stack.stackSize;
|
||||
return stack;
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.dispenseStack(source, stack);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stores the armor type: 0 is helmet, 1 is plate, 2 is legs and 3 is boots
|
||||
*/
|
||||
public final int armorType;
|
||||
|
||||
/** Holds the amount of damage that the armor reduces at full durability. */
|
||||
public final int damageReduceAmount;
|
||||
|
||||
/**
|
||||
* Used on RenderPlayer to select the correspondent armor to be rendered on the player: 0 is cloth, 1 is chain, 2 is
|
||||
* iron, 3 is diamond and 4 is gold.
|
||||
*/
|
||||
// public final int renderIndex;
|
||||
|
||||
/** The EnumArmorMaterial used for this ItemArmor */
|
||||
private final ToolMaterial material;
|
||||
private final String texture;
|
||||
|
||||
public ItemArmor(ToolMaterial material, String texture, int armorType)
|
||||
{
|
||||
this.material = material;
|
||||
this.texture = texture;
|
||||
this.armorType = armorType;
|
||||
// this.renderIndex = renderIndex;
|
||||
this.damageReduceAmount = material.getDamageReductionAmount(armorType);
|
||||
this.setMaxDamage(material.getDurability(armorType));
|
||||
this.maxStackSize = 1;
|
||||
this.setTab(CheatTab.tabCombat);
|
||||
DispenserRegistry.REGISTRY.putObject(this, dispenserBehavior);
|
||||
}
|
||||
|
||||
public int getColorFromItemStack(ItemStack stack, int renderPass)
|
||||
{
|
||||
if (renderPass > 0)
|
||||
{
|
||||
return 16777215;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = this.getArmorColor(stack);
|
||||
|
||||
if (i < 0)
|
||||
{
|
||||
i = 16777215;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enchantability factor of the item, most of the time is based on material.
|
||||
*/
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return this.material.getArmorEnchantability();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the armor material for this armor item.
|
||||
*/
|
||||
public ToolMaterial getArmorMaterial()
|
||||
{
|
||||
return this.material;
|
||||
}
|
||||
|
||||
public String getArmorTexture()
|
||||
{
|
||||
return this.texture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the specified armor ItemStack has a color.
|
||||
*/
|
||||
public boolean hasColor(ItemStack stack)
|
||||
{
|
||||
return this.material.canBeDyed() && stack.hasTagCompound() && stack.getTagCompound().hasKey("color", 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the color for the specified armor ItemStack.
|
||||
*/
|
||||
public int getArmorColor(ItemStack stack)
|
||||
{
|
||||
if (!this.material.canBeDyed())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||
|
||||
if (nbttagcompound != null && nbttagcompound.hasKey("color", 3))
|
||||
{
|
||||
// NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
|
||||
//
|
||||
// if (nbttagcompound1 != null && nbttagcompound1.hasKey("color", 3))
|
||||
// {
|
||||
return nbttagcompound.getInteger("color");
|
||||
// }
|
||||
}
|
||||
|
||||
return this.material.getDefaultColor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the color from the specified armor ItemStack.
|
||||
*/
|
||||
public void removeColor(ItemStack stack)
|
||||
{
|
||||
if (this.material.canBeDyed())
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||
|
||||
if (nbttagcompound != null)
|
||||
{
|
||||
// NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
|
||||
|
||||
if (nbttagcompound.hasKey("color"))
|
||||
{
|
||||
nbttagcompound.removeTag("color");
|
||||
if(nbttagcompound.hasNoTags())
|
||||
stack.setTagCompound(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of the specified armor ItemStack
|
||||
*/
|
||||
public void setColor(ItemStack stack, int color)
|
||||
{
|
||||
if (!this.material.canBeDyed())
|
||||
{
|
||||
throw new UnsupportedOperationException("Kann diese Rüstung nicht färben!");
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||
|
||||
if (nbttagcompound == null)
|
||||
{
|
||||
nbttagcompound = new NBTTagCompound();
|
||||
stack.setTagCompound(nbttagcompound);
|
||||
}
|
||||
|
||||
// NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
|
||||
//
|
||||
// if (!nbttagcompound.hasKey("display", 10))
|
||||
// {
|
||||
// nbttagcompound.setTag("display", nbttagcompound1);
|
||||
// }
|
||||
|
||||
nbttagcompound.setInteger("color", color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this item is repairable in an anvil.
|
||||
*/
|
||||
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
|
||||
{
|
||||
return this.material.isRepairItem(repair.getItem()) ? true : super.getIsRepairable(toRepair, repair);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
int i = ItemArmor.getArmorPosition(itemStackIn) - 1;
|
||||
ItemStack itemstack = playerIn.getArmor(i);
|
||||
|
||||
if (itemstack == null)
|
||||
{
|
||||
playerIn.setItem(i, itemStackIn.copy());
|
||||
itemStackIn.stackSize = 0;
|
||||
}
|
||||
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
// public boolean canBeDyed() {
|
||||
// return this.material.canBeDyed();
|
||||
// }
|
||||
|
||||
public Map<Attribute, Set<AttributeModifier>> getItemAttributeModifiers()
|
||||
{
|
||||
Map<Attribute, Set<AttributeModifier>> multimap = super.getItemAttributeModifiers();
|
||||
if(this.material.getRadiationReduction(this.armorType) > 0.0f)
|
||||
multimap.put(Attributes.RADIATION_RESISTANCE,
|
||||
Sets.newHashSet(new AttributeModifier(Attributes.ITEM_VAL_ID + (long)this.armorType + 1L, "Armor modifier " + (this.armorType + 1),
|
||||
(double)this.material.getRadiationReduction(this.armorType), false)));
|
||||
if(this.material.getMagicReduction(this.armorType) > 0.0f)
|
||||
multimap.put(Attributes.MAGIC_RESISTANCE,
|
||||
Sets.newHashSet(new AttributeModifier(Attributes.ITEM_VAL_ID + (long)this.armorType + 1L, "Armor modifier " + (this.armorType + 1),
|
||||
(double)this.material.getMagicReduction(this.armorType), false)));
|
||||
return multimap;
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return this.material.isMagnetic();
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return this.armorType == 0 ? Transforms.OFFSET2 : (this.armorType == 3 ? Transforms.OFFSET1 :
|
||||
super.getTransform());
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
if(this.material.canBeDyed())
|
||||
return new ModelBlock(this.getTransform(), name, name + "_overlay");
|
||||
else
|
||||
return super.getModel(name, meta);
|
||||
}
|
||||
|
||||
public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip) {
|
||||
if(this.material.canBeDyed()) {
|
||||
int color = this.material.getDefaultColor();
|
||||
if(stack.hasTagCompound() && stack.getTagCompound().hasKey("color", 3))
|
||||
color = stack.getTagCompound().getInteger("color");
|
||||
tooltip.add("Farbe: #" + Integer.toHexString(color).toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
// public Set<String> getValidTags() {
|
||||
// return Sets.newHashSet("color");
|
||||
// }
|
||||
|
||||
public static int getArmorPosition(ItemStack stack) {
|
||||
// if(stack.getItem() != ItemRegistry.getItemFromBlock(Blocks.pumpkin) && stack.getItem() != Items.skull) {
|
||||
if(stack.getItem() instanceof ItemArmor) {
|
||||
switch(((ItemArmor)stack.getItem()).armorType) {
|
||||
case 0:
|
||||
return 4;
|
||||
|
||||
case 1:
|
||||
return 3;
|
||||
|
||||
case 2:
|
||||
return 2;
|
||||
|
||||
case 3:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
// }
|
||||
// else {
|
||||
// return 4;
|
||||
// }
|
||||
}
|
||||
}
|
22
java/src/game/item/ItemAxe.java
Executable file
22
java/src/game/item/ItemAxe.java
Executable file
|
@ -0,0 +1,22 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.init.ToolMaterial;
|
||||
|
||||
public class ItemAxe extends ItemTool
|
||||
{
|
||||
// private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(new Block[] {
|
||||
// Blocks.planks, Blocks.bookshelf, Blocks.log, Blocks.log2, Blocks.chest, Blocks.pumpkin, Blocks.lit_pumpkin, Blocks.melon_block, Blocks.ladder
|
||||
// });
|
||||
|
||||
public ItemAxe(ToolMaterial material)
|
||||
{
|
||||
super(3, material);
|
||||
}
|
||||
|
||||
public boolean canUseOn(ItemStack stack, Block state)
|
||||
{
|
||||
return state.canAxeHarvest() /* state.getMaterial() != Material.wood && state.getMaterial() != Material.plants && state.getMaterial() != Material.vine ?
|
||||
super.getStrVsBlock(stack, state) */;
|
||||
}
|
||||
}
|
38
java/src/game/item/ItemBanHammer.java
Executable file
38
java/src/game/item/ItemBanHammer.java
Executable file
|
@ -0,0 +1,38 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.entity.DamageSource;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.world.BoundingBox;
|
||||
import game.world.Vec3;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public class ItemBanHammer extends ItemWand {
|
||||
public ItemBanHammer() {
|
||||
this.setColor(TextColor.DRED);
|
||||
}
|
||||
|
||||
public void onUse(ItemStack stack, EntityNPC player, WorldServer world, Vec3 vec) {
|
||||
List<EntityLiving> list = world.getEntitiesWithinAABB(EntityLiving.class, new BoundingBox(
|
||||
vec.xCoord - 3.5, vec.yCoord - 3.5, vec.zCoord - 3.5, vec.xCoord + 3.5, vec.yCoord + 3.5, vec.zCoord + 3.5));
|
||||
for(EntityLiving entity : list) {
|
||||
if(entity != player)
|
||||
entity.attackEntityFrom(DamageSource.causeExterminatusDamage(player), 1200);
|
||||
}
|
||||
for(int z = 0; z < 8; z++) {
|
||||
world.strikeLightning(vec.xCoord - 0.5 + world.rand.drange(-2.5, 2.5), vec.yCoord,
|
||||
vec.zCoord - 0.5 + world.rand.drange(-2.5, 2.5), 0x6f0000, 0, false, player);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getRange(ItemStack stack, EntityNPC player) {
|
||||
return 120;
|
||||
}
|
||||
}
|
220
java/src/game/item/ItemBanner.java
Executable file
220
java/src/game/item/ItemBanner.java
Executable file
|
@ -0,0 +1,220 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.ExtMath;
|
||||
import game.block.BlockStandingSign;
|
||||
import game.block.BlockWallSign;
|
||||
import game.color.DyeColor;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.model.ModelBakery;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.nbt.NBTTagList;
|
||||
import game.renderer.ItemMeshDefinition;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.tileentity.TileEntity;
|
||||
import game.tileentity.TileEntityBanner;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemBanner extends ItemBlock
|
||||
{
|
||||
public ItemBanner()
|
||||
{
|
||||
super(Blocks.banner);
|
||||
this.setTab(CheatTab.tabDeco);
|
||||
this.setHasSubtypes(true);
|
||||
this.setMaxDamage(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (side == Facing.DOWN)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!worldIn.getState(pos).getBlock().getMaterial().isSolid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = pos.offset(side);
|
||||
|
||||
if (!playerIn.canPlayerEdit(pos, side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!Blocks.banner.canPlaceBlockAt(worldIn, pos))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (worldIn.client)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (side == Facing.UP)
|
||||
{
|
||||
int i = ExtMath.floord((double)((playerIn.rotYaw + 180.0F) * 16.0F / 360.0F) + 0.5D) & 15;
|
||||
worldIn.setState(pos, Blocks.banner.getState().withProperty(BlockStandingSign.ROTATION, Integer.valueOf(i)), 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
worldIn.setState(pos, Blocks.wall_banner.getState().withProperty(BlockWallSign.FACING, side), 3);
|
||||
}
|
||||
|
||||
--stack.stackSize;
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentity instanceof TileEntityBanner)
|
||||
{
|
||||
((TileEntityBanner)tileentity).setItemValues(stack);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
// String s = "item.banner.";
|
||||
DyeColor enumdyecolor = this.getBaseColor(stack);
|
||||
// s = s + + ".name";
|
||||
return enumdyecolor.getSubject(0) + " " + super.getDisplay(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getSubCompound("BlockEntityTag", false);
|
||||
|
||||
if (nbttagcompound != null && nbttagcompound.hasKey("Patterns"))
|
||||
{
|
||||
NBTTagList nbttaglist = nbttagcompound.getTagList("Patterns", 10);
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount() && i < 6; ++i)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
|
||||
DyeColor enumdyecolor = DyeColor.byDyeDamage(nbttagcompound1.getInteger("Color"));
|
||||
TileEntityBanner.EnumBannerPattern pattern = TileEntityBanner.EnumBannerPattern.getPatternByID(nbttagcompound1.getString("Pattern"));
|
||||
|
||||
if (pattern != null)
|
||||
{
|
||||
tooltip.add(String.format(pattern.getDisplay(), pattern.isColorLowercase() ?
|
||||
enumdyecolor.getSubject(pattern.getDisplayType()).toLowerCase() : enumdyecolor.getSubject(pattern.getDisplayType())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getColorFromItemStack(ItemStack stack, int renderPass)
|
||||
{
|
||||
if (renderPass == 0)
|
||||
{
|
||||
return 16777215;
|
||||
}
|
||||
else
|
||||
{
|
||||
DyeColor enumdyecolor = this.getBaseColor(stack);
|
||||
return enumdyecolor.getColor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(Item itemIn, CheatTab tab, List<ItemStack> subItems)
|
||||
{
|
||||
for (DyeColor enumdyecolor : DyeColor.values())
|
||||
{
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
TileEntityBanner.setBaseColorAndPatterns(nbttagcompound, enumdyecolor.getDyeDamage(), (NBTTagList)null);
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setTag("BlockEntityTag", nbttagcompound);
|
||||
ItemStack itemstack = new ItemStack(itemIn, 1, enumdyecolor.getDyeDamage());
|
||||
itemstack.setTagCompound(nbttagcompound1);
|
||||
subItems.add(itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the tab this item is displayed on
|
||||
*/
|
||||
public CheatTab getTab()
|
||||
{
|
||||
return CheatTab.tabDeco;
|
||||
}
|
||||
|
||||
private DyeColor getBaseColor(ItemStack stack)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getSubCompound("BlockEntityTag", false);
|
||||
DyeColor enumdyecolor = null;
|
||||
|
||||
if (nbttagcompound != null && nbttagcompound.hasKey("Base"))
|
||||
{
|
||||
enumdyecolor = DyeColor.byDyeDamage(nbttagcompound.getInteger("Base"));
|
||||
}
|
||||
else
|
||||
{
|
||||
enumdyecolor = DyeColor.byDyeDamage(stack.getMetadata());
|
||||
}
|
||||
|
||||
return enumdyecolor;
|
||||
}
|
||||
|
||||
// protected boolean validateNbt(NBTTagCompound tag) {
|
||||
// if(tag.hasKey("BlockEntityTag")) {
|
||||
// if(!tag.hasKey("BlockEntityTag", 10)) {
|
||||
// return false;
|
||||
// }
|
||||
// NBTTagCompound etag = tag.getCompoundTag("BlockEntityTag");
|
||||
// if(etag.hasKey("Patterns")) {
|
||||
// if(!etag.hasKey("Patterns", 9)) {
|
||||
// return false;
|
||||
// }
|
||||
// NBTTagList patterns = etag.getTagList("Patterns", 10);
|
||||
// if(patterns.tagCount() > 16) {
|
||||
// NBTTagList npatterns = new NBTTagList();
|
||||
// for(int z = 0; z < 16; z++) {
|
||||
// npatterns.appendTag(patterns.get(z));
|
||||
// }
|
||||
// etag.setTag("Patterns", npatterns);
|
||||
// }
|
||||
// }
|
||||
// if(etag.hasKey("Base")) {
|
||||
// if(!etag.hasKey("Base", 3)) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public ItemMeshDefinition getMesher() {
|
||||
return new ItemMeshDefinition()
|
||||
{
|
||||
public String getModelLocation(ItemStack stack)
|
||||
{
|
||||
return "item/banner#0" + '#' + "inventory";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
|
||||
subItems.add(new ItemStack(itemIn, 1, 0));
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(ModelBakery.MODEL_ENTITY, this.getTransform());
|
||||
}
|
||||
}
|
85
java/src/game/item/ItemBed.java
Executable file
85
java/src/game/item/ItemBed.java
Executable file
|
@ -0,0 +1,85 @@
|
|||
package game.item;
|
||||
|
||||
import game.ExtMath;
|
||||
import game.block.Block;
|
||||
import game.block.BlockBed;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.State;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemBed extends Item
|
||||
{
|
||||
private final BlockBed bedBlock;
|
||||
|
||||
public ItemBed(BlockBed bedBlock)
|
||||
{
|
||||
this.bedBlock = bedBlock;
|
||||
this.setTab(CheatTab.tabDeco);
|
||||
}
|
||||
|
||||
public Block getBlock()
|
||||
{
|
||||
return this.bedBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (worldIn.client)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (side != Facing.UP)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
boolean flag = block.isReplaceable(worldIn, pos);
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
pos = pos.up();
|
||||
}
|
||||
|
||||
int i = ExtMath.floord((double)(playerIn.rotYaw * 4.0F / 360.0F) + 0.5D) & 3;
|
||||
Facing enumfacing = Facing.getHorizontal(i);
|
||||
BlockPos blockpos = pos.offset(enumfacing);
|
||||
|
||||
if (playerIn.canPlayerEdit(pos, side, stack) && playerIn.canPlayerEdit(blockpos, side, stack))
|
||||
{
|
||||
boolean flag1 = worldIn.getState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
|
||||
boolean flag2 = flag || worldIn.isAirBlock(pos);
|
||||
boolean flag3 = flag1 || worldIn.isAirBlock(blockpos);
|
||||
|
||||
if (flag2 && flag3 && worldIn.isBlockSolid(pos.down()) && worldIn.isBlockSolid(blockpos.down()))
|
||||
{
|
||||
State iblockstate1 = this.bedBlock.getState() /* .withProperty(BlockBed.OCCUPIED, Boolean.valueOf(false)) */ .withProperty(BlockBed.FACING, enumfacing).withProperty(BlockBed.PART, BlockBed.EnumPartType.FOOT);
|
||||
|
||||
if (worldIn.setState(pos, iblockstate1, 3))
|
||||
{
|
||||
State iblockstate2 = iblockstate1.withProperty(BlockBed.PART, BlockBed.EnumPartType.HEAD);
|
||||
worldIn.setState(blockpos, iblockstate2, 3);
|
||||
}
|
||||
|
||||
--stack.stackSize;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
224
java/src/game/item/ItemBlock.java
Executable file
224
java/src/game/item/ItemBlock.java
Executable file
|
@ -0,0 +1,224 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.block.Block;
|
||||
import game.color.TextColor;
|
||||
import game.entity.Entity;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.BlockRegistry;
|
||||
import game.init.Blocks;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.tileentity.TileEntity;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.State;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemBlock extends Item
|
||||
{
|
||||
protected final Block block;
|
||||
protected final String flatTexture;
|
||||
|
||||
public ItemBlock(Block block, String flatTexture)
|
||||
{
|
||||
this.block = block;
|
||||
this.flatTexture = flatTexture;
|
||||
}
|
||||
|
||||
public ItemBlock(Block block)
|
||||
{
|
||||
this(block, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the unlocalized name of this item to the string passed as the parameter, prefixed by "item."
|
||||
*/
|
||||
public ItemBlock setDisplay(String unlocalizedName)
|
||||
{
|
||||
super.setDisplay(unlocalizedName);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBlock setColor(TextColor color)
|
||||
{
|
||||
super.setColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (!block.isReplaceable(worldIn, pos))
|
||||
{
|
||||
pos = pos.offset(side);
|
||||
}
|
||||
|
||||
if (stack.stackSize == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!playerIn.canPlayerEdit(pos, side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (worldIn.canBlockBePlaced(this.block, pos, false, side, (Entity)null, stack))
|
||||
{
|
||||
int i = this.getMetadata(stack.getMetadata());
|
||||
State iblockstate1 = this.block.onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, i, playerIn);
|
||||
|
||||
if (worldIn.setState(pos, iblockstate1, 3))
|
||||
{
|
||||
iblockstate1 = worldIn.getState(pos);
|
||||
|
||||
if (iblockstate1.getBlock() == this.block)
|
||||
{
|
||||
setTileEntityNBT(worldIn, playerIn, pos, stack);
|
||||
this.block.onBlockPlacedBy(worldIn, pos, iblockstate1, playerIn, stack);
|
||||
}
|
||||
|
||||
worldIn.playSound(this.block.sound.getPlaceSound(), (double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), (this.block.sound.getVolume() + 1.0F) / 2.0F, this.block.sound.getFrequency() * 0.8F);
|
||||
--stack.stackSize;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean setTileEntityNBT(World worldIn, EntityNPC pos, BlockPos stack, ItemStack p_179224_3_)
|
||||
{
|
||||
// Server server = Server.getServer();
|
||||
//
|
||||
// if (server == null)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
if (p_179224_3_.hasTagCompound() && p_179224_3_.getTagCompound().hasKey("BlockEntityTag", 10))
|
||||
{
|
||||
TileEntity tileentity = worldIn.getTileEntity(stack);
|
||||
|
||||
if (tileentity != null)
|
||||
{
|
||||
if (!worldIn.client /* && tileentity.hasSpecialNBT() */ && !pos.connection.isAdmin())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttagcompound.copy();
|
||||
tileentity.writeToNBT(nbttagcompound);
|
||||
NBTTagCompound nbttagcompound2 = (NBTTagCompound)p_179224_3_.getTagCompound().getTag("BlockEntityTag");
|
||||
nbttagcompound.merge(nbttagcompound2);
|
||||
nbttagcompound.setInteger("x", stack.getX());
|
||||
nbttagcompound.setInteger("y", stack.getY());
|
||||
nbttagcompound.setInteger("z", stack.getZ());
|
||||
|
||||
if (!nbttagcompound.equals(nbttagcompound1))
|
||||
{
|
||||
tileentity.readFromNBT(nbttagcompound);
|
||||
tileentity.markDirty();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
// }
|
||||
}
|
||||
|
||||
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, Facing side, EntityNPC player, ItemStack stack)
|
||||
{
|
||||
Block block = worldIn.getState(pos).getBlock();
|
||||
|
||||
if (block == Blocks.snow_layer)
|
||||
{
|
||||
side = Facing.UP;
|
||||
}
|
||||
else if (!block.isReplaceable(worldIn, pos))
|
||||
{
|
||||
pos = pos.offset(side);
|
||||
}
|
||||
|
||||
return worldIn.canBlockBePlaced(this.block, pos, false, side, (Entity)null, stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
return this.block.getDisplay();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Returns the unlocalized name of this item.
|
||||
// */
|
||||
// public String getUnlocalizedName()
|
||||
// {
|
||||
// return this.block.getUnlocalizedName();
|
||||
// }
|
||||
|
||||
/**
|
||||
* gets the tab this item is displayed on
|
||||
*/
|
||||
public CheatTab getTab()
|
||||
{
|
||||
return this.block.getTab();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(Item itemIn, CheatTab tab, List<ItemStack> subItems)
|
||||
{
|
||||
this.block.getSubBlocks(itemIn, tab, subItems);
|
||||
}
|
||||
|
||||
public Block getBlock()
|
||||
{
|
||||
return this.block;
|
||||
}
|
||||
|
||||
// public Set<String> getValidTags() {
|
||||
// return Sets.newHashSet("BlockEntityTag");
|
||||
// }
|
||||
//
|
||||
// protected boolean validateNbt(NBTTagCompound tag) {
|
||||
// if(tag.hasKey("BlockEntityTag")) {
|
||||
// if(!tag.hasKey("BlockEntityTag", 10)) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return this.block.isMagnetic();
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return this.flatTexture != null ? super.getTransform() : this.block.getTransform();
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return this.flatTexture != null ? new ModelBlock(this.getTransform(), !this.flatTexture.isEmpty() ? this.flatTexture :
|
||||
this.block.getModel(BlockRegistry.REGISTRY.getNameForObject(this.block).toString(),
|
||||
this.block.getStateFromMeta(this.getMetadata(meta))).getPrimary() /* "blocks/" + name */) :
|
||||
new ModelBlock(this.block.getModel(BlockRegistry.REGISTRY.getNameForObject(this.block).toString(),
|
||||
this.block.getStateFromMeta(this.getMetadata(meta))), this.getTransform());
|
||||
}
|
||||
}
|
113
java/src/game/item/ItemBoat.java
Executable file
113
java/src/game/item/ItemBoat.java
Executable file
|
@ -0,0 +1,113 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.ExtMath;
|
||||
import game.entity.Entity;
|
||||
import game.entity.item.EntityBoat;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.world.BlockPos;
|
||||
import game.world.BoundingBox;
|
||||
import game.world.HitPosition;
|
||||
import game.world.Vec3;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemBoat extends Item
|
||||
{
|
||||
public ItemBoat()
|
||||
{
|
||||
this.maxStackSize = 1;
|
||||
this.setTab(CheatTab.tabSpawners);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
float f = 1.0F;
|
||||
float f1 = playerIn.prevPitch + (playerIn.rotPitch - playerIn.prevPitch) * f;
|
||||
float f2 = playerIn.prevYaw + (playerIn.rotYaw - playerIn.prevYaw) * f;
|
||||
double d0 = playerIn.prevX + (playerIn.posX - playerIn.prevX) * (double)f;
|
||||
double d1 = playerIn.prevY + (playerIn.posY - playerIn.prevY) * (double)f + (double)playerIn.getEyeHeight();
|
||||
double d2 = playerIn.prevZ + (playerIn.posZ - playerIn.prevZ) * (double)f;
|
||||
Vec3 vec3 = new Vec3(d0, d1, d2);
|
||||
float f3 = ExtMath.cos(-f2 * 0.017453292F - (float)Math.PI);
|
||||
float f4 = ExtMath.sin(-f2 * 0.017453292F - (float)Math.PI);
|
||||
float f5 = -ExtMath.cos(-f1 * 0.017453292F);
|
||||
float f6 = ExtMath.sin(-f1 * 0.017453292F);
|
||||
float f7 = f4 * f5;
|
||||
float f8 = f3 * f5;
|
||||
double d3 = 5.0D;
|
||||
Vec3 vec31 = vec3.addVector((double)f7 * d3, (double)f6 * d3, (double)f8 * d3);
|
||||
HitPosition movingobjectposition = worldIn.rayTraceBlocks(vec3, vec31, true);
|
||||
|
||||
if (movingobjectposition == null)
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
else
|
||||
{
|
||||
Vec3 vec32 = playerIn.getLook(f);
|
||||
boolean flag = false;
|
||||
float f9 = 1.0F;
|
||||
List<Entity> list = worldIn.getEntitiesWithinAABBExcludingEntity(playerIn, playerIn.getEntityBoundingBox().addCoord(vec32.xCoord * d3, vec32.yCoord * d3, vec32.zCoord * d3).expand((double)f9, (double)f9, (double)f9));
|
||||
|
||||
for (int i = 0; i < list.size(); ++i)
|
||||
{
|
||||
Entity entity = (Entity)list.get(i);
|
||||
|
||||
if (entity.canBeCollidedWith())
|
||||
{
|
||||
float f10 = entity.getCollisionBorderSize();
|
||||
BoundingBox axisalignedbb = entity.getEntityBoundingBox().expand((double)f10, (double)f10, (double)f10);
|
||||
|
||||
if (axisalignedbb.isVecInside(vec3))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (movingobjectposition.type == HitPosition.ObjectType.BLOCK)
|
||||
{
|
||||
BlockPos blockpos = movingobjectposition.block;
|
||||
|
||||
if (worldIn.getState(blockpos).getBlock() == Blocks.snow_layer)
|
||||
{
|
||||
blockpos = blockpos.down();
|
||||
}
|
||||
|
||||
EntityBoat entityboat = new EntityBoat(worldIn, (double)((float)blockpos.getX() + 0.5F), (double)((float)blockpos.getY() + 1.0F), (double)((float)blockpos.getZ() + 0.5F));
|
||||
entityboat.rotYaw = (float)(((ExtMath.floord((double)(playerIn.rotYaw * 4.0F / 360.0F) + 0.5D) & 3) - 1) * 90);
|
||||
|
||||
if (!worldIn.getCollidingBoundingBoxes(entityboat, entityboat.getEntityBoundingBox().expand(-0.1D, -0.1D, -0.1D)).isEmpty())
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
if (!worldIn.client)
|
||||
{
|
||||
worldIn.spawnEntityInWorld(entityboat);
|
||||
}
|
||||
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--itemStackIn.stackSize;
|
||||
// }
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
}
|
||||
|
||||
return itemStackIn;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
java/src/game/item/ItemBoltgun.java
Executable file
17
java/src/game/item/ItemBoltgun.java
Executable file
|
@ -0,0 +1,17 @@
|
|||
package game.item;
|
||||
|
||||
import game.init.Items;
|
||||
|
||||
public class ItemBoltgun extends ItemGunBase {
|
||||
public ItemBoltgun() {
|
||||
super(3072);
|
||||
}
|
||||
|
||||
public ItemAmmo getAmmo() {
|
||||
return Items.bolt;
|
||||
}
|
||||
|
||||
public float getVelocity() {
|
||||
return 8.0f;
|
||||
}
|
||||
}
|
20
java/src/game/item/ItemBook.java
Executable file
20
java/src/game/item/ItemBook.java
Executable file
|
@ -0,0 +1,20 @@
|
|||
package game.item;
|
||||
|
||||
public class ItemBook extends Item
|
||||
{
|
||||
/**
|
||||
* Checks isDamagable and if it cannot be stacked
|
||||
*/
|
||||
public boolean isItemTool(ItemStack stack)
|
||||
{
|
||||
return stack.stackSize == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enchantability factor of the item, most of the time is based on material.
|
||||
*/
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
154
java/src/game/item/ItemBow.java
Executable file
154
java/src/game/item/ItemBow.java
Executable file
|
@ -0,0 +1,154 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.enchantment.Enchantment;
|
||||
import game.enchantment.EnchantmentHelper;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.projectile.EntityArrow;
|
||||
import game.init.Items;
|
||||
import game.init.SoundEvent;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemBow extends Item
|
||||
{
|
||||
public ItemBow()
|
||||
{
|
||||
this.maxStackSize = 1;
|
||||
this.setMaxDamage(384);
|
||||
this.setTab(CheatTab.tabCombat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player stops using an Item (stops holding the right mouse button).
|
||||
*/
|
||||
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityNPC playerIn, int timeLeft)
|
||||
{
|
||||
boolean flag = /* playerIn.creative || */ EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;
|
||||
|
||||
if (flag || playerIn.inventory.hasItem(Items.arrow))
|
||||
{
|
||||
int i = this.getMaxItemUseDuration(stack) - timeLeft;
|
||||
float f = (float)i / 20.0F;
|
||||
f = (f * f + f * 2.0F) / 3.0F;
|
||||
|
||||
if ((double)f < 0.1D)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (f > 1.0F)
|
||||
{
|
||||
f = 1.0F;
|
||||
}
|
||||
|
||||
EntityArrow entityarrow = new EntityArrow(worldIn, playerIn, f * 2.0F);
|
||||
|
||||
if (f == 1.0F)
|
||||
{
|
||||
entityarrow.setIsCritical(true);
|
||||
}
|
||||
|
||||
int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
|
||||
|
||||
if (j > 0)
|
||||
{
|
||||
entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D);
|
||||
}
|
||||
|
||||
int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
|
||||
|
||||
if (k > 0)
|
||||
{
|
||||
entityarrow.setKnockbackStrength(k);
|
||||
}
|
||||
|
||||
if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0)
|
||||
{
|
||||
entityarrow.setFire(100);
|
||||
}
|
||||
|
||||
stack.damageItem(1, playerIn);
|
||||
worldIn.playSoundAtEntity(playerIn, SoundEvent.THROW, 1.0F, 1.0F / (itemRand.floatv() * 0.4F + 1.2F) + f * 0.5F);
|
||||
|
||||
if (flag)
|
||||
{
|
||||
entityarrow.canBePickedUp = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
playerIn.inventory.consumeInventoryItem(Items.arrow);
|
||||
}
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
|
||||
if (!worldIn.client)
|
||||
{
|
||||
worldIn.spawnEntityInWorld(entityarrow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
|
||||
* the Item before the action is complete.
|
||||
*/
|
||||
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long it takes to use or consume an item
|
||||
*/
|
||||
public int getMaxItemUseDuration(ItemStack stack)
|
||||
{
|
||||
return 72000;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the action that specifies what animation to play when the items is being used
|
||||
*/
|
||||
public ItemAction getItemUseAction(ItemStack stack)
|
||||
{
|
||||
return ItemAction.AIM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
if (/* playerIn.creative || */ playerIn.inventory.hasItem(Items.arrow))
|
||||
{
|
||||
playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn));
|
||||
}
|
||||
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enchantability factor of the item, most of the time is based on material.
|
||||
*/
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
|
||||
subItems.add(new ItemStack(itemIn, 1, 0));
|
||||
for(int z = 0; z < 3; z++) {
|
||||
subItems.add(new ItemStack(itemIn, 1, 1 + z));
|
||||
}
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.RANGED;
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(this.getTransform(), meta == 0 ? "bow" : ("bow_pulling_" + (meta - 1)));
|
||||
}
|
||||
}
|
346
java/src/game/item/ItemBucket.java
Executable file
346
java/src/game/item/ItemBucket.java
Executable file
|
@ -0,0 +1,346 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
|
||||
import game.block.Block;
|
||||
import game.block.BlockDynamicLiquid;
|
||||
import game.block.BlockLiquid;
|
||||
import game.block.BlockStaticLiquid;
|
||||
import game.collect.Sets;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.BlockRegistry;
|
||||
import game.init.Blocks;
|
||||
import game.init.FluidRegistry;
|
||||
import game.init.ItemRegistry;
|
||||
import game.init.Items;
|
||||
import game.init.SoundEvent;
|
||||
import game.material.Material;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.renderer.particle.ParticleType;
|
||||
import game.world.BlockPos;
|
||||
import game.world.HitPosition;
|
||||
import game.world.State;
|
||||
import game.world.Vec3i;
|
||||
import game.world.World;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public class ItemBucket extends Item
|
||||
{
|
||||
private final boolean recursive;
|
||||
private final BlockDynamicLiquid liquid;
|
||||
|
||||
private static boolean test(WorldServer world, BlockPos pos, Set<Block> blocks, int max, BlockPos origin, int radius) {
|
||||
if(pos.getY() < 0 || pos.getY() > max)
|
||||
return false;
|
||||
if(pos.getX() < origin.getX() - radius || pos.getX() > origin.getX() + radius)
|
||||
return false;
|
||||
if(pos.getY() < origin.getY() - radius || pos.getY() > origin.getY() + radius)
|
||||
return false;
|
||||
if(pos.getZ() < origin.getZ() - radius || pos.getZ() > origin.getZ() + radius)
|
||||
return false;
|
||||
Block block = world.getState(pos).getBlock();
|
||||
return blocks == null ? block instanceof BlockLiquid : blocks.contains(block);
|
||||
}
|
||||
|
||||
private static void setRecursive(WorldServer world, BlockPos origin, int radius, BlockStaticLiquid liquid) {
|
||||
Queue<BlockPos> queue = new ArrayDeque<BlockPos>();
|
||||
Set<BlockPos> visited = new HashSet<BlockPos>();
|
||||
List<Vec3i> dirs = new ArrayList<Vec3i>();
|
||||
Set<Block> blocks = liquid == null ? null : Sets.newHashSet(FluidRegistry.getDynamicBlock(liquid), liquid, Blocks.air);
|
||||
State state = (liquid == null ? Blocks.air : liquid).getState();
|
||||
int max = 511;
|
||||
|
||||
if(liquid != null) {
|
||||
dirs.add(new Vec3i(1, 0, 0));
|
||||
dirs.add(new Vec3i(-1, 0, 0));
|
||||
dirs.add(new Vec3i(0, 0, 1));
|
||||
dirs.add(new Vec3i(0, 0, -1));
|
||||
dirs.add(new Vec3i(0, -1, 0));
|
||||
max = Math.min(origin.getY(), max);
|
||||
}
|
||||
else {
|
||||
dirs.add(new Vec3i(0, -1, 0));
|
||||
dirs.add(new Vec3i(0, 1, 0));
|
||||
dirs.add(new Vec3i(-1, 0, 0));
|
||||
dirs.add(new Vec3i(1, 0, 0));
|
||||
dirs.add(new Vec3i(0, 0, -1));
|
||||
dirs.add(new Vec3i(0, 0, 1));
|
||||
}
|
||||
|
||||
for(int x = -1; x <= 1; x++) {
|
||||
for(int y = -1; y <= 1; y++) {
|
||||
for(int z = -1; z <= 1; z++) {
|
||||
BlockPos pos = new BlockPos(origin.getX() + x, origin.getY() + y, origin.getZ() + z);
|
||||
if (!visited.contains(pos)) {
|
||||
if(test(world, pos, blocks, max, origin, radius))
|
||||
queue.add(pos);
|
||||
visited.add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BlockPos loc;
|
||||
while ((loc = queue.poll()) != null) {
|
||||
world.setState(loc, state);
|
||||
for (Vec3i dir : dirs) {
|
||||
BlockPos pos = loc.add(dir);
|
||||
if (!visited.contains(pos)) {
|
||||
visited.add(pos);
|
||||
if (test(world, pos, blocks, max, origin, radius))
|
||||
queue.add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ItemBucket(BlockDynamicLiquid liquid, boolean recursive)
|
||||
{
|
||||
this.maxStackSize = liquid == null ? 16 : 1;
|
||||
this.liquid = liquid;
|
||||
this.recursive = recursive;
|
||||
this.setTab(CheatTab.tabTools);
|
||||
// if(!empty)
|
||||
// this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
public BlockDynamicLiquid getLiquid() {
|
||||
return this.liquid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
// boolean flag = this.fillBlock == Blocks.air;
|
||||
HitPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, this.liquid == null);
|
||||
|
||||
if (movingobjectposition == null)
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (movingobjectposition.type == HitPosition.ObjectType.BLOCK)
|
||||
{
|
||||
BlockPos blockpos = movingobjectposition.block;
|
||||
|
||||
if (!World.isValidXZ(blockpos))
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
if (this.liquid == null)
|
||||
{
|
||||
if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.side), movingobjectposition.side, itemStackIn))
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
State iblockstate = worldIn.getState(blockpos);
|
||||
Material material = iblockstate.getBlock().getMaterial();
|
||||
|
||||
// if (material == Material.water && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
|
||||
// {
|
||||
// worldIn.setBlockToAir(blockpos);
|
||||
// playerIn.triggerAchievement(StatList.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
// return this.fillBucket(itemStackIn, playerIn, new ItemStack(Items.water_bucket));
|
||||
// }
|
||||
// else if (material == Material.lava && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
|
||||
// {
|
||||
// worldIn.setBlockToAir(blockpos);
|
||||
// playerIn.triggerAchievement(StatList.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
// return this.fillBucket(itemStackIn, playerIn, new ItemStack(Items.lava_bucket));
|
||||
// }
|
||||
// else
|
||||
if(this.recursive) {
|
||||
if (material.isLiquid()) {
|
||||
if(!worldIn.client)
|
||||
setRecursive((WorldServer)worldIn, blockpos, 4, null);
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
// if(!playerIn.creative)
|
||||
--itemStackIn.stackSize;
|
||||
return itemStackIn;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (material.isLiquid() && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
|
||||
{
|
||||
worldIn.setBlockToAir(blockpos);
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
Block block = iblockstate.getBlock();
|
||||
return this.fillBucket(itemStackIn, playerIn, new ItemStack(
|
||||
ItemRegistry.getRegisteredItem(BlockRegistry.REGISTRY.getNameForObject(block instanceof BlockDynamicLiquid
|
||||
? FluidRegistry.getStaticBlock((BlockDynamicLiquid)block) : block) +
|
||||
"_bucket"), 1, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if (this.empty)
|
||||
// {
|
||||
// return new ItemStack(Items.bucket);
|
||||
// }
|
||||
|
||||
BlockPos blockpos1 = blockpos.offset(movingobjectposition.side);
|
||||
|
||||
if (!playerIn.canPlayerEdit(blockpos1, movingobjectposition.side, itemStackIn))
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
if (this.tryPlaceContainedLiquid(worldIn, blockpos1)) // && !playerIn.creative)
|
||||
{
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
if(this.recursive) {
|
||||
--itemStackIn.stackSize;
|
||||
return itemStackIn;
|
||||
}
|
||||
return new ItemStack(Items.bucket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return itemStackIn;
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack fillBucket(ItemStack emptyBuckets, EntityNPC player, ItemStack fullBucket)
|
||||
{
|
||||
// if (player.creative)
|
||||
// {
|
||||
// return emptyBuckets;
|
||||
// }
|
||||
// else
|
||||
if (--emptyBuckets.stackSize <= 0)
|
||||
{
|
||||
return fullBucket;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!player.inventory.addItemStackToInventory(fullBucket))
|
||||
{
|
||||
player.dropPlayerItemWithRandomChoice(fullBucket, false);
|
||||
}
|
||||
|
||||
return emptyBuckets;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean tryPlaceContainedLiquid(World worldIn, BlockPos pos)
|
||||
{
|
||||
if (this.liquid == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Material material = worldIn.getState(pos).getBlock().getMaterial();
|
||||
boolean flag = !material.isSolid();
|
||||
|
||||
if (!worldIn.isAirBlock(pos) && !flag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (worldIn.doesWaterVaporize(pos) && this.liquid.getMaterial() == Material.water)
|
||||
{
|
||||
int i = pos.getX();
|
||||
int j = pos.getY();
|
||||
int k = pos.getZ();
|
||||
worldIn.playSound(SoundEvent.FIZZ, (double)((float)i + 0.5F), (double)((float)j + 0.5F), (double)((float)k + 0.5F), 0.5F, 2.6F + (worldIn.rand.floatv() - worldIn.rand.floatv()) * 0.8F);
|
||||
|
||||
for (int l = 0; l < 8; ++l)
|
||||
{
|
||||
worldIn.spawnParticle(ParticleType.SMOKE_LARGE, (double)i + Math.random(), (double)j + Math.random(), (double)k + Math.random(), 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!worldIn.client && flag && !material.isLiquid())
|
||||
{
|
||||
worldIn.destroyBlock(pos, true);
|
||||
}
|
||||
|
||||
if(this.recursive) {
|
||||
if(!worldIn.client)
|
||||
setRecursive((WorldServer)worldIn, pos, 4, FluidRegistry.getStaticBlock(this.liquid));
|
||||
}
|
||||
else {
|
||||
worldIn.setState(pos, this.liquid.getState(), 3);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// public void getSubItems(Item itemIn, CreativeTab tab, List<ItemStack> subItems)
|
||||
// {
|
||||
// if(this.empty) {
|
||||
// super.getSubItems(itemIn, tab, subItems);
|
||||
// }
|
||||
// else {
|
||||
// for(int z = 0; z < FluidRegistry.getNumFluids(); z++) {
|
||||
// subItems.add(new ItemStack(itemIn, 1, z));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
String s = super.getDisplay(stack);
|
||||
if(this.liquid == null)
|
||||
return s;
|
||||
String s1 = this.liquid.getDisplay(); // FluidRegistry.getStaticBlock(this.liquid).getDisplay();
|
||||
if(s1 != null)
|
||||
s = s + " mit " + s1; // Strs.get("tile." + s1 + ".name");
|
||||
return s;
|
||||
}
|
||||
|
||||
// public int getColorFromItemStack(ItemStack stack, int renderPass)
|
||||
// {
|
||||
// return this.fillBlock == null && renderPass == 1 ? FluidRegistry.getLiquidColor(stack.getMetadata()) : 16777215;
|
||||
// }
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return this.recursive ? new ModelBlock(this.getTransform(), name.substring("recursive_".length())) : super.getModel(name, meta);
|
||||
}
|
||||
|
||||
// public ItemMeshDefinition getMesher() {
|
||||
// return this.fillBlock != null ? null : new ItemMeshDefinition()
|
||||
// {
|
||||
// public String getModelLocation(ItemStack stack)
|
||||
// {
|
||||
// return "item/fluid_bucket#0" + '#' + "inventory";
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
//
|
||||
// public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
|
||||
// if(this.fillBlock != null)
|
||||
// super.getRenderItems(itemIn, subItems);
|
||||
// else
|
||||
// subItems.add(new ItemStack(itemIn, 1, 0));
|
||||
// }
|
||||
|
||||
// public ModelBlock getModel(String name, int meta) {
|
||||
// if(this.empty)
|
||||
// return super.getModel(name, meta);
|
||||
// else
|
||||
// return new ModelBlock(this.getTransform(), meta < 0 || meta >= FluidRegistry.getNumFluids() ? "bucket" :
|
||||
// (BlockRegistry.REGISTRY.getNameForObject(FluidRegistry.getStaticBlock(meta)) + "_bucket"));
|
||||
// }
|
||||
}
|
77
java/src/game/item/ItemBucketMilk.java
Executable file
77
java/src/game/item/ItemBucketMilk.java
Executable file
|
@ -0,0 +1,77 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import game.collect.Sets;
|
||||
import game.entity.attributes.Attribute;
|
||||
import game.entity.attributes.AttributeModifier;
|
||||
import game.entity.attributes.Attributes;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Items;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemBucketMilk extends Item
|
||||
{
|
||||
public ItemBucketMilk()
|
||||
{
|
||||
this.setMaxStackSize(1);
|
||||
this.setTab(CheatTab.tabTools);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
|
||||
* the Item before the action is complete.
|
||||
*/
|
||||
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--stack.stackSize;
|
||||
// }
|
||||
|
||||
if (!worldIn.client)
|
||||
{
|
||||
playerIn.clearEffects(false);
|
||||
}
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return stack.stackSize <= 0 ? new ItemStack(Items.bucket) : stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long it takes to use or consume an item
|
||||
*/
|
||||
public int getMaxItemUseDuration(ItemStack stack)
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the action that specifies what animation to play when the items is being used
|
||||
*/
|
||||
public ItemAction getItemUseAction(ItemStack stack)
|
||||
{
|
||||
return ItemAction.DRINK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn));
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
public Map<Attribute, Set<AttributeModifier>> getItemInventoryModifiers()
|
||||
{
|
||||
Map<Attribute, Set<AttributeModifier>> multimap = super.getItemInventoryModifiers();
|
||||
multimap.put(Attributes.RADIATION, Sets.newHashSet(new AttributeModifier(Attributes.ITEM_VAL_ID, "Milk modifier", -5.0, false, true, true)));
|
||||
return multimap;
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return true;
|
||||
}
|
||||
}
|
19
java/src/game/item/ItemButton.java
Executable file
19
java/src/game/item/ItemButton.java
Executable file
|
@ -0,0 +1,19 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.BlockButton;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
|
||||
public class ItemButton extends ItemBlock {
|
||||
private final BlockButton button;
|
||||
|
||||
public ItemButton(BlockButton block) {
|
||||
super(block);
|
||||
this.button = block;
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(new ModelBlock(this.button.getTexture()).add(5, 6, 6, 11, 10, 10)
|
||||
.d().uv(5, 6, 11, 10).noCull().u().uv(5, 10, 11, 6).noCull()
|
||||
.ns().uv(5, 12, 11, 16).noCull().we().uv(6, 12, 10, 16).noCull(), this.getTransform());
|
||||
}
|
||||
}
|
32
java/src/game/item/ItemCamera.java
Executable file
32
java/src/game/item/ItemCamera.java
Executable file
|
@ -0,0 +1,32 @@
|
|||
package game.item;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.world.BlockPos;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemCamera extends ItemMagnetic {
|
||||
public ItemCamera() {
|
||||
this.setMaxStackSize(1);
|
||||
}
|
||||
|
||||
public boolean onAction(ItemStack stack, EntityNPC player, World world, ItemControl control, BlockPos block) {
|
||||
if(control == ItemControl.SECONDARY) {
|
||||
if(!world.client)
|
||||
world.playAuxSFX(1024, new BlockPos(player.posX, player.posY + player.getEyeHeight(), player.posZ), 0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// public final boolean canUseInAir() {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// public boolean ignoresBlocks() {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public boolean isFirstPerson() {
|
||||
return false;
|
||||
}
|
||||
}
|
65
java/src/game/item/ItemCarrotOnAStick.java
Executable file
65
java/src/game/item/ItemCarrotOnAStick.java
Executable file
|
@ -0,0 +1,65 @@
|
|||
package game.item;
|
||||
|
||||
import game.entity.animal.EntityPig;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Items;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemCarrotOnAStick extends Item
|
||||
{
|
||||
public ItemCarrotOnAStick()
|
||||
{
|
||||
this.setTab(CheatTab.tabTools);
|
||||
this.setMaxStackSize(1);
|
||||
this.setMaxDamage(25);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Returns True is the item is renderer in full 3D when hold.
|
||||
// */
|
||||
// public boolean isFull3D()
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Returns true if this item should be rotated by 180 degrees around the Y axis when being held in an entities
|
||||
// * hands.
|
||||
// */
|
||||
// public boolean shouldRotateAroundWhenRendering()
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
if (playerIn.isRiding() && playerIn.vehicle instanceof EntityPig)
|
||||
{
|
||||
EntityPig entitypig = (EntityPig)playerIn.vehicle;
|
||||
|
||||
if (entitypig.getAIControlledByPlayer().isControlledByPlayer() && itemStackIn.getMaxDamage() - itemStackIn.getMetadata() >= 7)
|
||||
{
|
||||
entitypig.getAIControlledByPlayer().boostSpeed();
|
||||
itemStackIn.damageItem(7, playerIn);
|
||||
|
||||
if (itemStackIn.stackSize == 0)
|
||||
{
|
||||
ItemStack itemstack = new ItemStack(Items.fishing_rod);
|
||||
itemstack.setTagCompound(itemStackIn.getTagCompound());
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.TOOL_FLIP;
|
||||
}
|
||||
}
|
159
java/src/game/item/ItemChargedOrb.java
Executable file
159
java/src/game/item/ItemChargedOrb.java
Executable file
|
@ -0,0 +1,159 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.BlockPortalFrame;
|
||||
import game.color.TextColor;
|
||||
import game.entity.item.EntityOrb;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.init.Items;
|
||||
import game.init.SoundEvent;
|
||||
import game.renderer.particle.ParticleType;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.State;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemChargedOrb extends ItemFragile
|
||||
{
|
||||
public ItemChargedOrb()
|
||||
{
|
||||
this.maxStackSize = 1;
|
||||
this.setTab(CheatTab.tabTools);
|
||||
this.setMaxDamage(16);
|
||||
this.setColor(TextColor.DMAGENTA);
|
||||
}
|
||||
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
// if (!playerIn.capabilities.isCreativeMode)
|
||||
// {
|
||||
// --itemStackIn.stackSize;
|
||||
// }
|
||||
if(itemStackIn.getItemDamage() >= this.getMaxDamage())
|
||||
return itemStackIn;
|
||||
itemStackIn.damageItem(1, playerIn);
|
||||
worldIn.playSoundAtEntity(playerIn, SoundEvent.THROW, 0.5F, 0.4F / (itemRand.floatv() * 0.4F + 0.8F));
|
||||
|
||||
if (!worldIn.client)
|
||||
{
|
||||
worldIn.spawnEntityInWorld(new EntityOrb(worldIn, playerIn));
|
||||
}
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return itemStackIn.getItemDamage() >= this.getMaxDamage() ? new ItemStack(Items.orb) : itemStackIn;
|
||||
}
|
||||
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
|
||||
if (stack.getItemDamage() == 0 && playerIn.canPlayerEdit(pos.offset(side), side, stack) /* && worldIn.dimension.getDimensionId() == 0 || worldIn.dimension.getDimensionId() == 1) */ && iblockstate.getBlock() == Blocks.portal_frame && !((Boolean)iblockstate.getValue(BlockPortalFrame.ORB)).booleanValue())
|
||||
{
|
||||
if (worldIn.client)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
worldIn.setState(pos, iblockstate.withProperty(BlockPortalFrame.ORB, Boolean.valueOf(true)), 2);
|
||||
worldIn.updateComparatorOutputLevel(pos, Blocks.portal_frame);
|
||||
--stack.stackSize;
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
double d0 = (double)((float)pos.getX() + (5.0F + itemRand.floatv() * 6.0F) / 16.0F);
|
||||
double d1 = (double)((float)pos.getY() + 0.8125F);
|
||||
double d2 = (double)((float)pos.getZ() + (5.0F + itemRand.floatv() * 6.0F) / 16.0F);
|
||||
double d3 = 0.0D;
|
||||
double d4 = 0.0D;
|
||||
double d5 = 0.0D;
|
||||
worldIn.spawnParticle(ParticleType.SMOKE_NORMAL, d0, d1, d2, d3, d4, d5);
|
||||
}
|
||||
|
||||
Facing enumfacing = (Facing)iblockstate.getValue(BlockPortalFrame.FACING);
|
||||
int l = 0;
|
||||
int j = 0;
|
||||
boolean flag1 = false;
|
||||
boolean flag = true;
|
||||
Facing enumfacing1 = enumfacing.rotateY();
|
||||
|
||||
for (int k = -2; k <= 2; ++k)
|
||||
{
|
||||
BlockPos blockpos1 = pos.offset(enumfacing1, k);
|
||||
State iblockstate1 = worldIn.getState(blockpos1);
|
||||
|
||||
if (iblockstate1.getBlock() == Blocks.portal_frame)
|
||||
{
|
||||
if (!((Boolean)iblockstate1.getValue(BlockPortalFrame.ORB)).booleanValue())
|
||||
{
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
|
||||
j = k;
|
||||
|
||||
if (!flag1)
|
||||
{
|
||||
l = k;
|
||||
flag1 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flag && j == l + 2)
|
||||
{
|
||||
BlockPos blockpos = pos.offset(enumfacing, 4);
|
||||
|
||||
for (int i1 = l; i1 <= j; ++i1)
|
||||
{
|
||||
BlockPos blockpos2 = blockpos.offset(enumfacing1, i1);
|
||||
State iblockstate3 = worldIn.getState(blockpos2);
|
||||
|
||||
if (iblockstate3.getBlock() != Blocks.portal_frame || !((Boolean)iblockstate3.getValue(BlockPortalFrame.ORB)).booleanValue())
|
||||
{
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j1 = l - 1; j1 <= j + 1; j1 += 4)
|
||||
{
|
||||
blockpos = pos.offset(enumfacing1, j1);
|
||||
|
||||
for (int l1 = 1; l1 <= 3; ++l1)
|
||||
{
|
||||
BlockPos blockpos3 = blockpos.offset(enumfacing, l1);
|
||||
State iblockstate2 = worldIn.getState(blockpos3);
|
||||
|
||||
if (iblockstate2.getBlock() != Blocks.portal_frame || !((Boolean)iblockstate2.getValue(BlockPortalFrame.ORB)).booleanValue())
|
||||
{
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
for (int k1 = l; k1 <= j; ++k1)
|
||||
{
|
||||
blockpos = pos.offset(enumfacing1, k1);
|
||||
|
||||
for (int i2 = 1; i2 <= 3; ++i2)
|
||||
{
|
||||
BlockPos blockpos4 = blockpos.offset(enumfacing, i2);
|
||||
worldIn.setState(blockpos4, Blocks.floor_portal.getState(), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
20
java/src/game/item/ItemChest.java
Executable file
20
java/src/game/item/ItemChest.java
Executable file
|
@ -0,0 +1,20 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.model.ModelBakery;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
|
||||
public class ItemChest extends ItemBlock {
|
||||
public ItemChest(Block block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(ModelBakery.MODEL_ENTITY, this.getTransform());
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.DEFAULT;
|
||||
}
|
||||
}
|
46
java/src/game/item/ItemCloth.java
Executable file
46
java/src/game/item/ItemCloth.java
Executable file
|
@ -0,0 +1,46 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.color.DyeColor;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
|
||||
public class ItemCloth extends ItemBlock
|
||||
{
|
||||
private final Integer display;
|
||||
|
||||
public ItemCloth(Block block, Integer display, String flatTexture)
|
||||
{
|
||||
super(block, flatTexture);
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
public ItemCloth(Block block, Integer display)
|
||||
{
|
||||
this(block, display, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
return DyeColor.byMetadata(stack.getMetadata()).getSubject(this.display) + " " + super.getDisplay(stack);
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return this.flatTexture != null ? new ModelBlock(this.getTransform(), "blocks/" + DyeColor.byMetadata(meta).getName() + "_" +
|
||||
this.flatTexture) : super.getModel(name, meta);
|
||||
}
|
||||
}
|
37
java/src/game/item/ItemCoal.java
Executable file
37
java/src/game/item/ItemCoal.java
Executable file
|
@ -0,0 +1,37 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
|
||||
public class ItemCoal extends Item
|
||||
{
|
||||
public ItemCoal()
|
||||
{
|
||||
this.setHasSubtypes(true);
|
||||
this.setMaxDamage(0);
|
||||
this.setTab(CheatTab.tabMetals);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
return stack.getMetadata() == 1 ? "Holzkohle" : super.getDisplay(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(Item itemIn, CheatTab tab, List<ItemStack> subItems)
|
||||
{
|
||||
subItems.add(new ItemStack(itemIn, 1, 0));
|
||||
subItems.add(new ItemStack(itemIn, 1, 1));
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(this.getTransform(), meta == 1 ? "charcoal" : "coal");
|
||||
}
|
||||
}
|
63
java/src/game/item/ItemColored.java
Executable file
63
java/src/game/item/ItemColored.java
Executable file
|
@ -0,0 +1,63 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
|
||||
public class ItemColored extends ItemBlock
|
||||
{
|
||||
private final Block coloredBlock;
|
||||
private String[] subtypeNames;
|
||||
|
||||
public ItemColored(Block block, boolean hasSubtypes, String flatTexture)
|
||||
{
|
||||
super(block, flatTexture);
|
||||
this.coloredBlock = block;
|
||||
|
||||
if (hasSubtypes)
|
||||
{
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
}
|
||||
|
||||
public ItemColored(Block block, boolean hasSubtypes)
|
||||
{
|
||||
this(block, hasSubtypes, null);
|
||||
}
|
||||
|
||||
public int getColorFromItemStack(ItemStack stack, int renderPass)
|
||||
{
|
||||
return this.coloredBlock.getRenderColor(this.coloredBlock.getStateFromMeta(stack.getMetadata()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
public ItemColored setSubtypeNames(String[] names)
|
||||
{
|
||||
this.subtypeNames = names;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
if (this.subtypeNames == null)
|
||||
{
|
||||
return super.getDisplay(stack);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = stack.getMetadata();
|
||||
return i >= 0 && i < this.subtypeNames.length ? this.subtypeNames[i] : super.getDisplay(stack);
|
||||
}
|
||||
}
|
||||
}
|
5
java/src/game/item/ItemControl.java
Executable file
5
java/src/game/item/ItemControl.java
Executable file
|
@ -0,0 +1,5 @@
|
|||
package game.item;
|
||||
|
||||
public enum ItemControl {
|
||||
PRIMARY, SECONDARY, TERTIARY, QUARTERNARY;
|
||||
}
|
66
java/src/game/item/ItemDie.java
Executable file
66
java/src/game/item/ItemDie.java
Executable file
|
@ -0,0 +1,66 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.ExtMath;
|
||||
import game.color.TextColor;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.projectile.EntityDie;
|
||||
import game.init.SoundEvent;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemDie extends Item
|
||||
{
|
||||
public static final int[] DIE_SIDES = new int[] {4, 6, 8, 10, 12, 20};
|
||||
public static final TextColor[] DIE_COLORS = new TextColor[] {TextColor.DGREEN, TextColor.NEON, TextColor.DMAGENTA,
|
||||
TextColor.MAGENTA, TextColor.DRED, TextColor.ORANGE};
|
||||
|
||||
public ItemDie()
|
||||
{
|
||||
this.setTab(CheatTab.tabTools);
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--itemStackIn.stackSize;
|
||||
// }
|
||||
|
||||
worldIn.playSoundAtEntity(playerIn, SoundEvent.THROW, 0.5F, 0.4F / (itemRand.floatv() * 0.4F + 0.8F));
|
||||
|
||||
if (!worldIn.client)
|
||||
{
|
||||
worldIn.spawnEntityInWorld(new EntityDie(worldIn, playerIn, DIE_SIDES[ExtMath.clampi(itemStackIn.getMetadata(),
|
||||
0, DIE_SIDES.length - 1)], false)); // playerIn.creative));
|
||||
}
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
public void getSubItems(Item itemIn, CheatTab tab, List<ItemStack> subItems)
|
||||
{
|
||||
for(int z = 0; z < DIE_SIDES.length; z++) {
|
||||
subItems.add(new ItemStack(itemIn, 1, z));
|
||||
}
|
||||
}
|
||||
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
return super.getDisplay(stack) + " W" + DIE_SIDES[ExtMath.clampi(stack.getMetadata(), 0, DIE_SIDES.length - 1)];
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.DICE;
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(new ModelBlock("items/die_d" + DIE_SIDES[meta] + "_side").add().nswe()
|
||||
.du("items/die_d" + DIE_SIDES[meta] + "_top"), this.getTransform());
|
||||
}
|
||||
}
|
13
java/src/game/item/ItemDispenser.java
Executable file
13
java/src/game/item/ItemDispenser.java
Executable file
|
@ -0,0 +1,13 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
|
||||
public class ItemDispenser extends ItemBlock {
|
||||
public ItemDispenser(Block block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
public int getMetadata(int damage) {
|
||||
return 2;
|
||||
}
|
||||
}
|
97
java/src/game/item/ItemDoor.java
Executable file
97
java/src/game/item/ItemDoor.java
Executable file
|
@ -0,0 +1,97 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.block.BlockDoor;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.material.Material;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.State;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemDoor extends Item
|
||||
{
|
||||
private Block block;
|
||||
|
||||
public ItemDoor(Block block)
|
||||
{
|
||||
this.block = block;
|
||||
this.setTab(block.getMaterial() == Material.wood ? CheatTab.tabWood : CheatTab.tabTech);
|
||||
}
|
||||
|
||||
public Block getBlock()
|
||||
{
|
||||
return this.block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (side != Facing.UP)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (!block.isReplaceable(worldIn, pos))
|
||||
{
|
||||
pos = pos.offset(side);
|
||||
}
|
||||
|
||||
if (!playerIn.canPlayerEdit(pos, side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!this.block.canPlaceBlockAt(worldIn, pos))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
placeDoor(worldIn, pos, Facing.fromAngle((double)playerIn.rotYaw), this.block, true);
|
||||
--stack.stackSize;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void placeDoor(World worldIn, BlockPos pos, Facing facing, Block door, boolean update)
|
||||
{
|
||||
BlockPos blockpos = pos.offset(facing.rotateY());
|
||||
BlockPos blockpos1 = pos.offset(facing.rotateYCCW());
|
||||
int i = (worldIn.getState(blockpos1).getBlock().isNormalCube() ? 1 : 0) + (worldIn.getState(blockpos1.up()).getBlock().isNormalCube() ? 1 : 0);
|
||||
int j = (worldIn.getState(blockpos).getBlock().isNormalCube() ? 1 : 0) + (worldIn.getState(blockpos.up()).getBlock().isNormalCube() ? 1 : 0);
|
||||
boolean flag = worldIn.getState(blockpos1).getBlock() == door || worldIn.getState(blockpos1.up()).getBlock() == door;
|
||||
boolean flag1 = worldIn.getState(blockpos).getBlock() == door || worldIn.getState(blockpos.up()).getBlock() == door;
|
||||
boolean flag2 = false;
|
||||
|
||||
if (flag && !flag1 || j > i)
|
||||
{
|
||||
flag2 = true;
|
||||
}
|
||||
|
||||
BlockPos blockpos2 = pos.up();
|
||||
State iblockstate = door.getState().withProperty(BlockDoor.FACING, facing).withProperty(BlockDoor.HINGE, flag2 ? BlockDoor.EnumHingePosition.RIGHT : BlockDoor.EnumHingePosition.LEFT);
|
||||
worldIn.setState(pos, iblockstate.withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.LOWER), 2);
|
||||
worldIn.setState(blockpos2, iblockstate.withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.UPPER), 2);
|
||||
if(update) {
|
||||
worldIn.notifyNeighborsOfStateChange(pos, door);
|
||||
worldIn.notifyNeighborsOfStateChange(blockpos2, door);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return this.block == Blocks.iron_door;
|
||||
}
|
||||
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
return this.block.getDisplay();
|
||||
}
|
||||
}
|
29
java/src/game/item/ItemDoublePlant.java
Executable file
29
java/src/game/item/ItemDoublePlant.java
Executable file
|
@ -0,0 +1,29 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import game.block.Block;
|
||||
import game.block.BlockDoublePlant;
|
||||
import game.block.BlockDoublePlant.EnumPlantType;
|
||||
import game.color.Colorizer;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
|
||||
public class ItemDoublePlant extends ItemMultiTexture
|
||||
{
|
||||
public ItemDoublePlant(Block block, Block block2, Function<ItemStack, String> nameFunction)
|
||||
{
|
||||
super(block, block2, true, nameFunction);
|
||||
}
|
||||
|
||||
public int getColorFromItemStack(ItemStack stack, int renderPass)
|
||||
{
|
||||
BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = BlockDoublePlant.EnumPlantType.byMetadata(stack.getMetadata());
|
||||
return blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN ? super.getColorFromItemStack(stack, renderPass) : Colorizer.getGrassColor(0.5D, 1.0D);
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(this.getTransform(), "blocks/" + (
|
||||
BlockDoublePlant.EnumPlantType.byMetadata(meta) == EnumPlantType.SUNFLOWER ? "sunflower_front" :
|
||||
BlockDoublePlant.EnumPlantType.byMetadata(meta).getName() + "_top"));
|
||||
}
|
||||
}
|
235
java/src/game/item/ItemDye.java
Executable file
235
java/src/game/item/ItemDye.java
Executable file
|
@ -0,0 +1,235 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.block.Block;
|
||||
import game.block.BlockBed;
|
||||
import game.block.IGrowable;
|
||||
import game.color.DyeColor;
|
||||
import game.entity.animal.EntitySheep;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.init.BlockRegistry;
|
||||
import game.init.Blocks;
|
||||
import game.material.Material;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.renderer.particle.ParticleType;
|
||||
import game.tileentity.TileEntity;
|
||||
import game.tileentity.TileEntityBeacon;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.State;
|
||||
import game.world.World;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public class ItemDye extends Item
|
||||
{
|
||||
public static final int[] dyeColors = new int[] {1973019, 11743532, 3887386, 5320730, 2437522, 8073150, 2651799, 11250603, 4408131, 14188952, 4312372, 14602026, 6719955, 12801229, 15435844, 15790320};
|
||||
|
||||
public ItemDye()
|
||||
{
|
||||
this.setHasSubtypes(true);
|
||||
this.setMaxDamage(0);
|
||||
this.setTab(CheatTab.tabMaterials);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
int i = stack.getMetadata();
|
||||
return DyeColor.byDyeDamage(i).getDye();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (!playerIn.canPlayerEdit(pos.offset(side), side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
DyeColor enumdyecolor = DyeColor.byDyeDamage(stack.getMetadata());
|
||||
|
||||
if (enumdyecolor == DyeColor.WHITE)
|
||||
{
|
||||
if (applyBonemeal(stack, worldIn, pos))
|
||||
{
|
||||
if (!worldIn.client)
|
||||
{
|
||||
worldIn.playAuxSFX(2005, pos, 0);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (enumdyecolor == DyeColor.BROWN)
|
||||
{
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (block == Blocks.jungle_log) // && iblockstate.getValue(BlockPlanks.VARIANT) == BlockPlanks.EnumType.JUNGLE)
|
||||
{
|
||||
if (side == Facing.DOWN)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (side == Facing.UP)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
pos = pos.offset(side);
|
||||
|
||||
if (worldIn.isAirBlock(pos))
|
||||
{
|
||||
State iblockstate1 = Blocks.cocoa.onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, 0, playerIn);
|
||||
worldIn.setState(pos, iblockstate1, 2);
|
||||
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--stack.stackSize;
|
||||
// }
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
if(iblockstate.getBlock() instanceof BlockBed) {
|
||||
Block bedBlock = BlockRegistry.getByNameOrId(enumdyecolor.getName() + "_bed");
|
||||
if(bedBlock != null) {
|
||||
if (iblockstate.getValue(BlockBed.PART) == BlockBed.EnumPartType.FOOT)
|
||||
{
|
||||
pos = pos.offset(iblockstate.getValue(BlockBed.FACING));
|
||||
iblockstate = worldIn.getState(pos);
|
||||
if(!(iblockstate.getBlock() instanceof BlockBed)) // || iblockstate.getValue(BlockBed.OCCUPIED))
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
// if(iblockstate.getValue(BlockBed.OCCUPIED))
|
||||
// return false;
|
||||
if(!(worldIn.getState(pos.offset(iblockstate.getValue(BlockBed.FACING).getOpposite())).getBlock() instanceof BlockBed))
|
||||
return false;
|
||||
}
|
||||
State iblockstate1 = bedBlock.getState()
|
||||
.withProperty(BlockBed.FACING, iblockstate.getValue(BlockBed.FACING))
|
||||
.withProperty(BlockBed.PART, BlockBed.EnumPartType.FOOT);
|
||||
// .withProperty(BlockBed.OCCUPIED, false);
|
||||
if(worldIn.setState(pos.offset(iblockstate.getValue(BlockBed.FACING).getOpposite()), iblockstate1, 2)) {
|
||||
iblockstate1 = iblockstate1.withProperty(BlockBed.PART, BlockBed.EnumPartType.HEAD);
|
||||
worldIn.setState(pos, iblockstate1, 2);
|
||||
}
|
||||
// if(!playerIn.creative)
|
||||
--stack.stackSize;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(iblockstate.getBlock() == Blocks.beacon) {
|
||||
TileEntity te = worldIn.getTileEntity(pos);
|
||||
if(te instanceof TileEntityBeacon) {
|
||||
((TileEntityBeacon)te).setBeamColor(enumdyecolor);
|
||||
// if(!playerIn.creative)
|
||||
--stack.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean applyBonemeal(ItemStack stack, World worldIn, BlockPos target)
|
||||
{
|
||||
State iblockstate = worldIn.getState(target);
|
||||
|
||||
if (iblockstate.getBlock() instanceof IGrowable)
|
||||
{
|
||||
IGrowable igrowable = (IGrowable)iblockstate.getBlock();
|
||||
|
||||
if (igrowable.canGrow(worldIn, target, iblockstate, worldIn.client))
|
||||
{
|
||||
if (!worldIn.client)
|
||||
{
|
||||
if (igrowable.canUseBonemeal(worldIn, worldIn.rand, target, iblockstate))
|
||||
{
|
||||
igrowable.grow((WorldServer)worldIn, worldIn.rand, target, iblockstate);
|
||||
}
|
||||
|
||||
--stack.stackSize;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void spawnBonemealParticles(World worldIn, BlockPos pos, int amount)
|
||||
{
|
||||
if (amount == 0)
|
||||
{
|
||||
amount = 15;
|
||||
}
|
||||
|
||||
Block block = worldIn.getState(pos).getBlock();
|
||||
|
||||
if (block.getMaterial() != Material.air)
|
||||
{
|
||||
block.setBlockBoundsBasedOnState(worldIn, pos);
|
||||
|
||||
for (int i = 0; i < amount; ++i)
|
||||
{
|
||||
double d0 = itemRand.gaussian() * 0.02D;
|
||||
double d1 = itemRand.gaussian() * 0.02D;
|
||||
double d2 = itemRand.gaussian() * 0.02D;
|
||||
worldIn.spawnParticle(ParticleType.GROW, (double)((float)pos.getX() + itemRand.floatv()), (double)pos.getY() + (double)itemRand.floatv() * block.getBlockBoundsMaxY(), (double)((float)pos.getZ() + itemRand.floatv()), d0, d1, d2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the item can be used on the given entity, e.g. shears on sheep.
|
||||
*/
|
||||
public boolean itemInteractionForEntity(ItemStack stack, EntityNPC playerIn, EntityLiving target)
|
||||
{
|
||||
if (target instanceof EntitySheep)
|
||||
{
|
||||
EntitySheep entitysheep = (EntitySheep)target;
|
||||
DyeColor enumdyecolor = DyeColor.byDyeDamage(stack.getMetadata());
|
||||
|
||||
if (!entitysheep.getSheared() && entitysheep.getFleeceColor() != enumdyecolor)
|
||||
{
|
||||
entitysheep.setFleeceColor(enumdyecolor);
|
||||
--stack.stackSize;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(Item itemIn, CheatTab tab, List<ItemStack> subItems)
|
||||
{
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
subItems.add(new ItemStack(itemIn, 1, i));
|
||||
}
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(this.getTransform(), "dye_" + DyeColor.byDyeDamage(meta).getName());
|
||||
}
|
||||
}
|
60
java/src/game/item/ItemDynamite.java
Executable file
60
java/src/game/item/ItemDynamite.java
Executable file
|
@ -0,0 +1,60 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.projectile.EntityDynamite;
|
||||
import game.init.SoundEvent;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemDynamite extends Item
|
||||
{
|
||||
private static final String[] TIERS = new String[] {"II", "III", "IV", "V", "VI", "VII", "VIII"};
|
||||
|
||||
public ItemDynamite()
|
||||
{
|
||||
this.maxStackSize = 32;
|
||||
this.setTab(CheatTab.tabTools);
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--itemStackIn.stackSize;
|
||||
// }
|
||||
|
||||
worldIn.playSoundAtEntity(playerIn, SoundEvent.THROW, 0.5F, 0.4F / (itemRand.floatv() * 0.4F + 0.8F));
|
||||
|
||||
if (!worldIn.client)
|
||||
{
|
||||
worldIn.spawnEntityInWorld(new EntityDynamite(worldIn, playerIn, itemStackIn.getMetadata()));
|
||||
}
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
public void getSubItems(Item itemIn, CheatTab tab, List<ItemStack> subItems)
|
||||
{
|
||||
for(int z = 0; z < 8; z++) {
|
||||
subItems.add(new ItemStack(itemIn, 1, z));
|
||||
}
|
||||
}
|
||||
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
int exp = stack.getMetadata() & 7;
|
||||
return super.getDisplay(stack) + (exp == 0 ? "" : " " + TIERS[exp-1]);
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(this.getTransform(), "dynamite" + (meta == 0 ? "" : ("_" + meta)));
|
||||
}
|
||||
}
|
42
java/src/game/item/ItemEditWand.java
Executable file
42
java/src/game/item/ItemEditWand.java
Executable file
|
@ -0,0 +1,42 @@
|
|||
package game.item;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.world.BlockPos;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemEditWand extends Item {
|
||||
public ItemEditWand() {
|
||||
this.maxStackSize = 1;
|
||||
this.setTab(CheatTab.tabTools);
|
||||
}
|
||||
|
||||
// public boolean canBreakBlocks() {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// public boolean ignoresBlocks() {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public boolean hasEffect(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public boolean onAction(ItemStack stack, EntityNPC player, World world, ItemControl control, BlockPos block) {
|
||||
if(!world.client && control == ItemControl.TERTIARY && player.connection.isAdmin())
|
||||
player.connection.setSelectMode();
|
||||
if(!world.client && (control == ItemControl.PRIMARY || control == ItemControl.SECONDARY) && player.connection.isAdmin())
|
||||
player.connection.setSelection(control == ItemControl.PRIMARY, block);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.TOOL;
|
||||
}
|
||||
}
|
9
java/src/game/item/ItemEffect.java
Executable file
9
java/src/game/item/ItemEffect.java
Executable file
|
@ -0,0 +1,9 @@
|
|||
package game.item;
|
||||
|
||||
public class ItemEffect extends Item
|
||||
{
|
||||
public boolean hasEffect(ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
35
java/src/game/item/ItemEgg.java
Executable file
35
java/src/game/item/ItemEgg.java
Executable file
|
@ -0,0 +1,35 @@
|
|||
package game.item;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.projectile.EntityEgg;
|
||||
import game.init.SoundEvent;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemEgg extends Item
|
||||
{
|
||||
public ItemEgg()
|
||||
{
|
||||
this.setTab(CheatTab.tabTools);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--itemStackIn.stackSize;
|
||||
// }
|
||||
|
||||
worldIn.playSoundAtEntity(playerIn, SoundEvent.THROW, 0.5F, 0.4F / (itemRand.floatv() * 0.4F + 0.8F));
|
||||
|
||||
if (!worldIn.client)
|
||||
{
|
||||
worldIn.spawnEntityInWorld(new EntityEgg(worldIn, playerIn));
|
||||
}
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return itemStackIn;
|
||||
}
|
||||
}
|
207
java/src/game/item/ItemEnchantedBook.java
Executable file
207
java/src/game/item/ItemEnchantedBook.java
Executable file
|
@ -0,0 +1,207 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.enchantment.Enchantment;
|
||||
import game.enchantment.EnchantmentHelper;
|
||||
import game.enchantment.RngEnchantment;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Items;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.nbt.NBTTagList;
|
||||
import game.renderer.ItemMeshDefinition;
|
||||
import game.rng.Random;
|
||||
|
||||
public class ItemEnchantedBook extends Item
|
||||
{
|
||||
public ItemEnchantedBook() {
|
||||
this.setColor(TextColor.YELLOW);
|
||||
}
|
||||
|
||||
public boolean hasEffect(ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks isDamagable and if it cannot be stacked
|
||||
*/
|
||||
public boolean isItemTool(ItemStack stack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void getSubItems(Item itemIn, CheatTab tab, List<ItemStack> subItems)
|
||||
{
|
||||
for (Enchantment enchantment : Enchantment.enchantmentsBookList) {
|
||||
if(enchantment != null && enchantment.type != null)
|
||||
subItems.add(Items.enchanted_book.getEnchantedItemStack(new RngEnchantment(enchantment, enchantment.getMaxLevel())));
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Return an item rarity from EnumRarity
|
||||
// */
|
||||
// public ChatFormat getColor(ItemStack stack)
|
||||
// {
|
||||
// return this.getEnchantments(stack).tagCount() > 0 ? ChatFormat.YELLOW : super.getColor(stack);
|
||||
// }
|
||||
|
||||
public NBTTagList getEnchantments(ItemStack stack)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||
return nbttagcompound != null && nbttagcompound.hasKey("StoredEnchantments", 9) ? (NBTTagList)nbttagcompound.getTag("StoredEnchantments") : new NBTTagList();
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip)
|
||||
{
|
||||
super.addInformation(stack, playerIn, tooltip);
|
||||
NBTTagList nbttaglist = this.getEnchantments(stack);
|
||||
|
||||
if (nbttaglist != null)
|
||||
{
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
{
|
||||
int j = nbttaglist.getCompoundTagAt(i).getShort("id");
|
||||
int k = nbttaglist.getCompoundTagAt(i).getShort("lvl");
|
||||
|
||||
if (Enchantment.getEnchantmentById(j) != null)
|
||||
{
|
||||
tooltip.add(Enchantment.getEnchantmentById(j).getFormattedName(k));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an stored enchantment to an enchanted book ItemStack
|
||||
*/
|
||||
public void addEnchantment(ItemStack stack, RngEnchantment enchantment)
|
||||
{
|
||||
NBTTagList nbttaglist = this.getEnchantments(stack);
|
||||
boolean flag = true;
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
|
||||
|
||||
if (nbttagcompound.getShort("id") == enchantment.enchantmentobj.effectId)
|
||||
{
|
||||
if (nbttagcompound.getShort("lvl") < enchantment.enchantmentLevel)
|
||||
{
|
||||
nbttagcompound.setShort("lvl", (short)enchantment.enchantmentLevel);
|
||||
}
|
||||
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setShort("id", (short)enchantment.enchantmentobj.effectId);
|
||||
nbttagcompound1.setShort("lvl", (short)enchantment.enchantmentLevel);
|
||||
nbttaglist.appendTag(nbttagcompound1);
|
||||
}
|
||||
|
||||
if (!stack.hasTagCompound())
|
||||
{
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
stack.getTagCompound().setTag("StoredEnchantments", nbttaglist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ItemStack of an enchanted version of this item.
|
||||
*/
|
||||
public ItemStack getEnchantedItemStack(RngEnchantment data)
|
||||
{
|
||||
ItemStack itemstack = new ItemStack(this);
|
||||
this.addEnchantment(itemstack, data);
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
public void getAll(Enchantment enchantment, List<ItemStack> list)
|
||||
{
|
||||
for (int i = enchantment.getMinLevel(); i <= enchantment.getMaxLevel(); ++i)
|
||||
{
|
||||
list.add(this.getEnchantedItemStack(new RngEnchantment(enchantment, i)));
|
||||
}
|
||||
}
|
||||
|
||||
public RngLoot getRandom(Random rand)
|
||||
{
|
||||
return this.getRandom(rand, 1, 1, 1);
|
||||
}
|
||||
|
||||
public RngLoot getRandom(Random rand, int minChance, int maxChance, int weight)
|
||||
{
|
||||
ItemStack itemstack = new ItemStack(Items.book, 1, 0);
|
||||
EnchantmentHelper.addRandomEnchantment(rand, itemstack, 30);
|
||||
return new RngLoot(itemstack, minChance, maxChance, weight);
|
||||
}
|
||||
|
||||
// public Set<String> getValidTags() {
|
||||
// return Sets.newHashSet("StoredEnchantments");
|
||||
// }
|
||||
//
|
||||
// protected boolean validateNbt(NBTTagCompound tag) {
|
||||
// if(tag.hasKey("StoredEnchantments")) {
|
||||
// if(!tag.hasKey("StoredEnchantments", 9)) {
|
||||
// return false;
|
||||
// }
|
||||
// NBTTagList ench = tag.getTagList("StoredEnchantments", 10);
|
||||
// if(ench.hasNoTags()) {
|
||||
// return false;
|
||||
// }
|
||||
// if(ench.tagCount() > Enchantment.getNames().size()) {
|
||||
// return false;
|
||||
// }
|
||||
// Enchantment[] ecn = new Enchantment[ench.tagCount()];
|
||||
// for(int e = 0; e < ench.tagCount(); e++) {
|
||||
// NBTTagCompound ec = ench.getCompoundTagAt(e);
|
||||
// if(ec.getKeySet().size() != 2 || !ec.hasKey("id", 2) || !ec.hasKey("lvl", 2)) {
|
||||
// return false;
|
||||
// }
|
||||
// int id = ec.getShort("id");
|
||||
// int lvl = ec.getShort("lvl");
|
||||
// Enchantment en = Enchantment.getEnchantmentById(id);
|
||||
// if(en == null) {
|
||||
// return false;
|
||||
// }
|
||||
//// if(!adv && (lvl < en.getMinLevel() || lvl > en.getMaxLevel())) {
|
||||
//// return false;
|
||||
//// }
|
||||
// ecn[e] = en;
|
||||
// }
|
||||
// for(int e = 0; e < ecn.length; e++) {
|
||||
// for(int f = 0; f < ecn.length; f++) {
|
||||
// if(f != e && ecn[e] == ecn[f]) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public ItemMeshDefinition getMesher() {
|
||||
return new ItemMeshDefinition()
|
||||
{
|
||||
public String getModelLocation(ItemStack stack)
|
||||
{
|
||||
return "item/enchanted_book#0" + '#' + "inventory";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
|
||||
subItems.add(new ItemStack(itemIn, 1, 0));
|
||||
}
|
||||
}
|
40
java/src/game/item/ItemExpBottle.java
Executable file
40
java/src/game/item/ItemExpBottle.java
Executable file
|
@ -0,0 +1,40 @@
|
|||
package game.item;
|
||||
|
||||
import game.entity.item.EntityXpBottle;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.SoundEvent;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemExpBottle extends Item
|
||||
{
|
||||
public ItemExpBottle()
|
||||
{
|
||||
this.setTab(CheatTab.tabTools);
|
||||
}
|
||||
|
||||
public boolean hasEffect(ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--itemStackIn.stackSize;
|
||||
// }
|
||||
|
||||
worldIn.playSoundAtEntity(playerIn, SoundEvent.THROW, 0.5F, 0.4F / (itemRand.floatv() * 0.4F + 0.8F));
|
||||
|
||||
if (!worldIn.client)
|
||||
{
|
||||
worldIn.spawnEntityInWorld(new EntityXpBottle(worldIn, playerIn));
|
||||
}
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return itemStackIn;
|
||||
}
|
||||
}
|
41
java/src/game/item/ItemExterminator.java
Executable file
41
java/src/game/item/ItemExterminator.java
Executable file
|
@ -0,0 +1,41 @@
|
|||
package game.item;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.dimension.Space;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.SoundEvent;
|
||||
import game.world.World;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public class ItemExterminator extends ItemMagnetic {
|
||||
public ItemExterminator() {
|
||||
this.setMaxStackSize(1);
|
||||
this.setColor(TextColor.DRED);
|
||||
}
|
||||
|
||||
// public final boolean canUseInAir() {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityNPC player) {
|
||||
if(!world.client) {
|
||||
world.playSoundAtEntity(player, SoundEvent.CLICK, 1.0F, 2.0F);
|
||||
if(world.dimension == Space.INSTANCE)
|
||||
player.connection.addFeed(TextColor.RED + "Der Weltraum kann nicht zerstört werden (lol)");
|
||||
else if(!((WorldServer)world).exterminate())
|
||||
player.connection.addFeed(TextColor.YELLOW + "Die Welt %s ist bereits zerstört", world.dimension.getFormattedName(false));
|
||||
else
|
||||
player.connection.addFeed(TextColor.CRIMSON + "Die Welt %s wurde vernichtet >:)-", world.dimension.getFormattedName(false));
|
||||
|
||||
// if (!playerIn.capabilities.isCreativeMode)
|
||||
// {
|
||||
// --stack.stackSize;
|
||||
// }
|
||||
|
||||
// return true;
|
||||
}
|
||||
|
||||
// player.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return stack;
|
||||
}
|
||||
}
|
43
java/src/game/item/ItemFence.java
Executable file
43
java/src/game/item/ItemFence.java
Executable file
|
@ -0,0 +1,43 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.block.BlockFence;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
|
||||
public class ItemFence extends ItemBlock {
|
||||
public ItemFence(Block block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(new ModelBlock(((BlockFence)this.block).getTexture()).noOcclude()
|
||||
.add(6, 0, 0, 10, 16, 4)
|
||||
.d().uv(6, 0, 10, 4)
|
||||
.u().uv(6, 0, 10, 4).noCull()
|
||||
.n().uv(6, 0, 10, 16).noCull()
|
||||
.s().uv(6, 0, 10, 16).noCull()
|
||||
.w().uv(0, 0, 4, 16).noCull()
|
||||
.e().uv(0, 0, 4, 16).noCull()
|
||||
.add(6, 0, 12, 10, 16, 16)
|
||||
.d().uv(6, 12, 10, 16)
|
||||
.u().uv(6, 12, 10, 16).noCull()
|
||||
.n().uv(6, 0, 10, 16).noCull()
|
||||
.s().uv(6, 0, 10, 16).noCull()
|
||||
.w().uv(12, 0, 16, 16).noCull()
|
||||
.e().uv(12, 0, 16, 16).noCull()
|
||||
.add(7, 13, -2, 9, 15, 18)
|
||||
.d().uv(7, 0, 9, 16).noCull()
|
||||
.u().uv(7, 0, 9, 16).noCull()
|
||||
.n().uv(7, 1, 9, 3).noCull()
|
||||
.s().uv(7, 1, 9, 3).noCull()
|
||||
.w().uv(0, 1, 16, 3).noCull()
|
||||
.e().uv(0, 1, 16, 3).noCull()
|
||||
.add(7, 5, -2, 9, 7, 18)
|
||||
.d().uv(7, 0, 9, 16).noCull()
|
||||
.u().uv(7, 0, 9, 16).noCull()
|
||||
.n().uv(7, 9, 9, 11).noCull()
|
||||
.s().uv(7, 9, 9, 11).noCull()
|
||||
.w().uv(0, 9, 16, 11).noCull()
|
||||
.e().uv(0, 9, 16, 11).noCull(), this.getTransform());
|
||||
}
|
||||
}
|
52
java/src/game/item/ItemFireball.java
Executable file
52
java/src/game/item/ItemFireball.java
Executable file
|
@ -0,0 +1,52 @@
|
|||
package game.item;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.init.SoundEvent;
|
||||
import game.material.Material;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemFireball extends Item
|
||||
{
|
||||
public ItemFireball()
|
||||
{
|
||||
this.setTab(CheatTab.tabTools);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (worldIn.client)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = pos.offset(side);
|
||||
|
||||
if (!playerIn.canPlayerEdit(pos, side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (worldIn.getState(pos).getBlock().getMaterial() == Material.air)
|
||||
{
|
||||
worldIn.playSound(SoundEvent.FIREBALL, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 1.0F, (itemRand.floatv() - itemRand.floatv()) * 0.2F + 1.0F);
|
||||
worldIn.setState(pos, Blocks.fire.getState());
|
||||
}
|
||||
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--stack.stackSize;
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
83
java/src/game/item/ItemFirework.java
Executable file
83
java/src/game/item/ItemFirework.java
Executable file
|
@ -0,0 +1,83 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.collect.Lists;
|
||||
import game.entity.item.EntityFireworks;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.nbt.NBTTagList;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemFirework extends Item
|
||||
{
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (!worldIn.client)
|
||||
{
|
||||
EntityFireworks entityfireworkrocket = new EntityFireworks(worldIn, (double)((float)pos.getX() + hitX), (double)((float)pos.getY() + hitY), (double)((float)pos.getZ() + hitZ), stack);
|
||||
worldIn.spawnEntityInWorld(entityfireworkrocket);
|
||||
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--stack.stackSize;
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip)
|
||||
{
|
||||
if (stack.hasTagCompound())
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound().getCompoundTag("Fireworks");
|
||||
|
||||
if (nbttagcompound != null)
|
||||
{
|
||||
if (nbttagcompound.hasKey("Flight", 99))
|
||||
{
|
||||
tooltip.add("Flugdauer: " + nbttagcompound.getByte("Flight"));
|
||||
}
|
||||
|
||||
NBTTagList nbttaglist = nbttagcompound.getTagList("Explosions", 10);
|
||||
|
||||
if (nbttaglist != null && nbttaglist.tagCount() > 0)
|
||||
{
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
|
||||
List<String> list = Lists.<String>newArrayList();
|
||||
ItemFireworkCharge.addExplosionInfo(nbttagcompound1, list);
|
||||
|
||||
if (list.size() > 0)
|
||||
{
|
||||
for (int j = 1; j < ((List)list).size(); ++j)
|
||||
{
|
||||
list.set(j, " " + (String)list.get(j));
|
||||
}
|
||||
|
||||
tooltip.addAll(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// public Set<String> getValidTags() {
|
||||
// return Sets.newHashSet("Fireworks");
|
||||
// }
|
||||
}
|
199
java/src/game/item/ItemFireworkCharge.java
Executable file
199
java/src/game/item/ItemFireworkCharge.java
Executable file
|
@ -0,0 +1,199 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.color.DyeColor;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.nbt.NBTBase;
|
||||
import game.nbt.NBTTagCompound;
|
||||
import game.nbt.NBTTagIntArray;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
|
||||
public class ItemFireworkCharge extends Item
|
||||
{
|
||||
private static final String[] EXPLOSIONS = new String[] {"Kleine Kugel", "Große Kugel", "Stern", "Pentagramm", "Explosion"};
|
||||
|
||||
public int getColorFromItemStack(ItemStack stack, int renderPass)
|
||||
{
|
||||
if (renderPass != 1)
|
||||
{
|
||||
return super.getColorFromItemStack(stack, renderPass);
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTBase nbtbase = getExplosionTag(stack, "Colors");
|
||||
|
||||
if (!(nbtbase instanceof NBTTagIntArray))
|
||||
{
|
||||
return 9079434;
|
||||
}
|
||||
else
|
||||
{
|
||||
NBTTagIntArray nbttagintarray = (NBTTagIntArray)nbtbase;
|
||||
int[] aint = nbttagintarray.getIntArray();
|
||||
|
||||
if (aint.length == 1)
|
||||
{
|
||||
return aint[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int k = 0;
|
||||
|
||||
for (int l : aint)
|
||||
{
|
||||
i += (l & 16711680) >> 16;
|
||||
j += (l & 65280) >> 8;
|
||||
k += (l & 255) >> 0;
|
||||
}
|
||||
|
||||
i = i / aint.length;
|
||||
j = j / aint.length;
|
||||
k = k / aint.length;
|
||||
return i << 16 | j << 8 | k;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static NBTBase getExplosionTag(ItemStack stack, String key)
|
||||
{
|
||||
if (stack.hasTagCompound())
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound().getCompoundTag("Explosion");
|
||||
|
||||
if (nbttagcompound != null)
|
||||
{
|
||||
return nbttagcompound.getTag(key);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip)
|
||||
{
|
||||
if (stack.hasTagCompound())
|
||||
{
|
||||
NBTTagCompound nbttagcompound = stack.getTagCompound().getCompoundTag("Explosion");
|
||||
|
||||
if (nbttagcompound != null)
|
||||
{
|
||||
addExplosionInfo(nbttagcompound, tooltip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addExplosionInfo(NBTTagCompound nbt, List<String> tooltip)
|
||||
{
|
||||
byte b0 = nbt.getByte("Type");
|
||||
|
||||
if (b0 >= 0 && b0 <= 4)
|
||||
{
|
||||
tooltip.add(EXPLOSIONS[b0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
tooltip.add("Unbekannte Form");
|
||||
}
|
||||
|
||||
int[] aint = nbt.getIntArray("Colors");
|
||||
|
||||
if (aint.length > 0)
|
||||
{
|
||||
boolean flag = true;
|
||||
String s = "";
|
||||
|
||||
for (int i : aint)
|
||||
{
|
||||
if (!flag)
|
||||
{
|
||||
s = s + ", ";
|
||||
}
|
||||
|
||||
flag = false;
|
||||
boolean flag1 = false;
|
||||
|
||||
for (int j = 0; j < ItemDye.dyeColors.length; ++j)
|
||||
{
|
||||
if (i == ItemDye.dyeColors[j])
|
||||
{
|
||||
flag1 = true;
|
||||
s = s + DyeColor.byDyeDamage(j).getDisplay();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag1)
|
||||
{
|
||||
s = s + "Benutzerdefiniert";
|
||||
}
|
||||
}
|
||||
|
||||
tooltip.add(s);
|
||||
}
|
||||
|
||||
int[] aint1 = nbt.getIntArray("FadeColors");
|
||||
|
||||
if (aint1.length > 0)
|
||||
{
|
||||
boolean flag2 = true;
|
||||
String s1 = "Übergang zu ";
|
||||
|
||||
for (int l : aint1)
|
||||
{
|
||||
if (!flag2)
|
||||
{
|
||||
s1 = s1 + ", ";
|
||||
}
|
||||
|
||||
flag2 = false;
|
||||
boolean flag5 = false;
|
||||
|
||||
for (int k = 0; k < 16; ++k)
|
||||
{
|
||||
if (l == ItemDye.dyeColors[k])
|
||||
{
|
||||
flag5 = true;
|
||||
s1 = s1 + DyeColor.byDyeDamage(k).getDisplay();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag5)
|
||||
{
|
||||
s1 = s1 + "Benutzerdefiniert";
|
||||
}
|
||||
}
|
||||
|
||||
tooltip.add(s1);
|
||||
}
|
||||
|
||||
boolean flag3 = nbt.getBoolean("Trail");
|
||||
|
||||
if (flag3)
|
||||
{
|
||||
tooltip.add("Schweif");
|
||||
}
|
||||
|
||||
boolean flag4 = nbt.getBoolean("Flicker");
|
||||
|
||||
if (flag4)
|
||||
{
|
||||
tooltip.add("Funkeln");
|
||||
}
|
||||
}
|
||||
|
||||
// public Set<String> getValidTags() {
|
||||
// return Sets.newHashSet("Explosion");
|
||||
// }
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(this.getTransform(), "firework_charge", "firework_charge_overlay");
|
||||
}
|
||||
}
|
160
java/src/game/item/ItemFishFood.java
Executable file
160
java/src/game/item/ItemFishFood.java
Executable file
|
@ -0,0 +1,160 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import game.collect.Maps;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.potion.Potion;
|
||||
import game.potion.PotionEffect;
|
||||
import game.potion.PotionHelper;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemFishFood extends ItemFood
|
||||
{
|
||||
/** Indicates whether this fish is "cooked" or not. */
|
||||
private final boolean cooked;
|
||||
|
||||
public ItemFishFood(boolean cooked)
|
||||
{
|
||||
super(0, false);
|
||||
this.cooked = cooked;
|
||||
}
|
||||
|
||||
public int getHealAmount(ItemStack stack)
|
||||
{
|
||||
ItemFishFood.FishType itemfishfood$fishtype = ItemFishFood.FishType.byItemStack(stack);
|
||||
return this.cooked && itemfishfood$fishtype.canCook() ? itemfishfood$fishtype.getCookedHealAmount() : itemfishfood$fishtype.getUncookedHealAmount();
|
||||
}
|
||||
|
||||
public String getPotionEffect(ItemStack stack)
|
||||
{
|
||||
return ItemFishFood.FishType.byItemStack(stack) == ItemFishFood.FishType.PUFFERFISH ? PotionHelper.pufferfishEffect : null;
|
||||
}
|
||||
|
||||
protected void onFoodEaten(ItemStack stack, World worldIn, EntityNPC player)
|
||||
{
|
||||
ItemFishFood.FishType itemfishfood$fishtype = ItemFishFood.FishType.byItemStack(stack);
|
||||
|
||||
if (itemfishfood$fishtype == ItemFishFood.FishType.PUFFERFISH)
|
||||
{
|
||||
player.addEffect(new PotionEffect(Potion.poison.id, 1200, 3));
|
||||
player.addEffect(new PotionEffect(Potion.confusion.id, 300, 1));
|
||||
}
|
||||
|
||||
super.onFoodEaten(stack, worldIn, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(Item itemIn, CheatTab tab, List<ItemStack> subItems)
|
||||
{
|
||||
for (ItemFishFood.FishType itemfishfood$fishtype : ItemFishFood.FishType.values())
|
||||
{
|
||||
if (!this.cooked || itemfishfood$fishtype.canCook())
|
||||
{
|
||||
subItems.add(new ItemStack(this, 1, itemfishfood$fishtype.getMetadata()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
ItemFishFood.FishType type = ItemFishFood.FishType.byItemStack(stack);
|
||||
return (type.canCook() ? (this.cooked ? "Gebratener " : "Roher ") : "") + type.getName();
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(this.getTransform(), (this.cooked ? "cooked_" : "") + FishType.byMetadata(meta).getTexture());
|
||||
}
|
||||
|
||||
public static enum FishType
|
||||
{
|
||||
COD("cod", 0, "Kabeljau", 2, 5),
|
||||
SALMON("salmon", 1, "Lachs", 2, 6),
|
||||
CLOWNFISH("clownfish", 2, "Clownfisch", 1),
|
||||
PUFFERFISH("pufferfish", 3, "Kugelfisch", 1);
|
||||
|
||||
private static final Map<Integer, ItemFishFood.FishType> META_LOOKUP = Maps.<Integer, ItemFishFood.FishType>newHashMap();
|
||||
private final int meta;
|
||||
private final String texture;
|
||||
private final String name;
|
||||
private final int uncookedHealAmount;
|
||||
private final int cookedHealAmount;
|
||||
private boolean cookable = false;
|
||||
|
||||
private FishType(String texture, int meta, String name, int uncookedHeal, int cookedHeal)
|
||||
{
|
||||
this.texture = texture;
|
||||
this.meta = meta;
|
||||
this.name = name;
|
||||
this.uncookedHealAmount = uncookedHeal;
|
||||
this.cookedHealAmount = cookedHeal;
|
||||
this.cookable = true;
|
||||
}
|
||||
|
||||
private FishType(String texture, int meta, String name, int uncookedHeal)
|
||||
{
|
||||
this.texture = texture;
|
||||
this.meta = meta;
|
||||
this.name = name;
|
||||
this.uncookedHealAmount = uncookedHeal;
|
||||
this.cookedHealAmount = 0;
|
||||
this.cookable = false;
|
||||
}
|
||||
|
||||
public int getMetadata()
|
||||
{
|
||||
return this.meta;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getTexture()
|
||||
{
|
||||
return this.texture;
|
||||
}
|
||||
|
||||
public int getUncookedHealAmount()
|
||||
{
|
||||
return this.uncookedHealAmount;
|
||||
}
|
||||
|
||||
public int getCookedHealAmount()
|
||||
{
|
||||
return this.cookedHealAmount;
|
||||
}
|
||||
|
||||
public boolean canCook()
|
||||
{
|
||||
return this.cookable;
|
||||
}
|
||||
|
||||
public static ItemFishFood.FishType byMetadata(int meta)
|
||||
{
|
||||
ItemFishFood.FishType itemfishfood$fishtype = (ItemFishFood.FishType)META_LOOKUP.get(Integer.valueOf(meta));
|
||||
return itemfishfood$fishtype == null ? COD : itemfishfood$fishtype;
|
||||
}
|
||||
|
||||
public static ItemFishFood.FishType byItemStack(ItemStack stack)
|
||||
{
|
||||
return stack.getItem() instanceof ItemFishFood ? byMetadata(stack.getMetadata()) : COD;
|
||||
}
|
||||
|
||||
static {
|
||||
for (ItemFishFood.FishType itemfishfood$fishtype : values())
|
||||
{
|
||||
META_LOOKUP.put(Integer.valueOf(itemfishfood$fishtype.getMetadata()), itemfishfood$fishtype);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
93
java/src/game/item/ItemFishingRod.java
Executable file
93
java/src/game/item/ItemFishingRod.java
Executable file
|
@ -0,0 +1,93 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.projectile.EntityHook;
|
||||
import game.init.SoundEvent;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemFishingRod extends Item
|
||||
{
|
||||
public ItemFishingRod()
|
||||
{
|
||||
this.setMaxDamage(64);
|
||||
this.setMaxStackSize(1);
|
||||
this.setTab(CheatTab.tabTools);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Returns True is the item is renderer in full 3D when hold.
|
||||
// */
|
||||
// public boolean isFull3D()
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Returns true if this item should be rotated by 180 degrees around the Y axis when being held in an entities
|
||||
// * hands.
|
||||
// */
|
||||
// public boolean shouldRotateAroundWhenRendering()
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
if (playerIn.fishEntity != null)
|
||||
{
|
||||
int i = playerIn.fishEntity.handleHookRetraction();
|
||||
itemStackIn.damageItem(i, playerIn);
|
||||
playerIn.swingItem();
|
||||
}
|
||||
else
|
||||
{
|
||||
worldIn.playSoundAtEntity(playerIn, SoundEvent.THROW, 0.5F, 0.4F / (itemRand.floatv() * 0.4F + 0.8F));
|
||||
|
||||
if (!worldIn.client)
|
||||
{
|
||||
worldIn.spawnEntityInWorld(new EntityHook(worldIn, playerIn));
|
||||
}
|
||||
|
||||
playerIn.swingItem();
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
}
|
||||
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks isDamagable and if it cannot be stacked
|
||||
*/
|
||||
public boolean isItemTool(ItemStack stack)
|
||||
{
|
||||
return super.isItemTool(stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enchantability factor of the item, most of the time is based on material.
|
||||
*/
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
|
||||
subItems.add(new ItemStack(itemIn, 1, 0));
|
||||
subItems.add(new ItemStack(itemIn, 1, 1));
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.TOOL_FLIP;
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(this.getTransform(), meta == 1 ? "fishing_rod_cast" : "fishing_rod");
|
||||
}
|
||||
}
|
47
java/src/game/item/ItemFlintAndSteel.java
Executable file
47
java/src/game/item/ItemFlintAndSteel.java
Executable file
|
@ -0,0 +1,47 @@
|
|||
package game.item;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.init.SoundEvent;
|
||||
import game.material.Material;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemFlintAndSteel extends Item
|
||||
{
|
||||
public ItemFlintAndSteel()
|
||||
{
|
||||
this.maxStackSize = 1;
|
||||
this.setMaxDamage(64);
|
||||
this.setTab(CheatTab.tabTools);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
pos = pos.offset(side);
|
||||
|
||||
if (!playerIn.canPlayerEdit(pos, side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (worldIn.getState(pos).getBlock().getMaterial() == Material.air)
|
||||
{
|
||||
worldIn.playSound(SoundEvent.IGNITE, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 1.0F, itemRand.floatv() * 0.4F + 0.8F);
|
||||
worldIn.setState(pos, Blocks.fire.getState());
|
||||
}
|
||||
|
||||
stack.damageItem(1, playerIn);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return true;
|
||||
}
|
||||
}
|
99
java/src/game/item/ItemFood.java
Executable file
99
java/src/game/item/ItemFood.java
Executable file
|
@ -0,0 +1,99 @@
|
|||
package game.item;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.SoundEvent;
|
||||
import game.potion.PotionEffect;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemFood extends Item
|
||||
{
|
||||
public final int itemUseDuration;
|
||||
private final int healAmount;
|
||||
private final boolean isWolfsFavoriteMeat;
|
||||
private int potionId;
|
||||
private int potionDuration;
|
||||
private int potionAmplifier;
|
||||
private float potionEffectProbability;
|
||||
|
||||
public ItemFood(int amount, boolean isWolfFood)
|
||||
{
|
||||
this.itemUseDuration = 32;
|
||||
this.healAmount = amount;
|
||||
this.isWolfsFavoriteMeat = isWolfFood;
|
||||
this.setTab(CheatTab.tabMisc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
|
||||
* the Item before the action is complete.
|
||||
*/
|
||||
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
// if(!playerIn.creative)
|
||||
--stack.stackSize;
|
||||
worldIn.playSoundAtEntity(playerIn, SoundEvent.EAT, 0.5F, worldIn.rand.floatv() * 0.1F + 0.9F);
|
||||
playerIn.heal((int)((float)this.getHealAmount(stack) * 0.5f * (1.0f + worldIn.rand.floatv())));
|
||||
this.onFoodEaten(stack, worldIn, playerIn);
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return stack;
|
||||
}
|
||||
|
||||
protected void onFoodEaten(ItemStack stack, World worldIn, EntityNPC player)
|
||||
{
|
||||
if (!worldIn.client && this.potionId > 0 && worldIn.rand.floatv() < this.potionEffectProbability)
|
||||
{
|
||||
player.addEffect(new PotionEffect(this.potionId, this.potionDuration * 20, this.potionAmplifier));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* How long it takes to use or consume an item
|
||||
*/
|
||||
public int getMaxItemUseDuration(ItemStack stack)
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the action that specifies what animation to play when the items is being used
|
||||
*/
|
||||
public ItemAction getItemUseAction(ItemStack stack)
|
||||
{
|
||||
return ItemAction.EAT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn));
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
public int getHealAmount(ItemStack stack)
|
||||
{
|
||||
return this.healAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether wolves like this food (true for raw and cooked porkchop).
|
||||
*/
|
||||
public boolean isWolfsFavoriteMeat()
|
||||
{
|
||||
return this.isWolfsFavoriteMeat;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets a potion effect on the item. Args: int potionId, int duration (will be multiplied by 20), int amplifier,
|
||||
* float probability of effect happening
|
||||
*/
|
||||
public ItemFood setPotionEffect(int id, int duration, int amplifier, float probability)
|
||||
{
|
||||
this.potionId = id;
|
||||
this.potionDuration = duration;
|
||||
this.potionAmplifier = amplifier;
|
||||
this.potionEffectProbability = probability;
|
||||
return this;
|
||||
}
|
||||
}
|
7
java/src/game/item/ItemFragile.java
Executable file
7
java/src/game/item/ItemFragile.java
Executable file
|
@ -0,0 +1,7 @@
|
|||
package game.item;
|
||||
|
||||
public class ItemFragile extends Item {
|
||||
public boolean isFragile() {
|
||||
return true;
|
||||
}
|
||||
}
|
69
java/src/game/item/ItemGlassBottle.java
Executable file
69
java/src/game/item/ItemGlassBottle.java
Executable file
|
@ -0,0 +1,69 @@
|
|||
package game.item;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Items;
|
||||
import game.material.Material;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.world.BlockPos;
|
||||
import game.world.HitPosition;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemGlassBottle extends Item
|
||||
{
|
||||
public ItemGlassBottle()
|
||||
{
|
||||
this.setTab(CheatTab.tabTools);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
HitPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true);
|
||||
|
||||
if (movingobjectposition == null)
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (movingobjectposition.type == HitPosition.ObjectType.BLOCK)
|
||||
{
|
||||
BlockPos blockpos = movingobjectposition.block;
|
||||
|
||||
if (!World.isValidXZ(blockpos))
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.side), movingobjectposition.side, itemStackIn))
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
if (worldIn.getState(blockpos).getBlock().getMaterial() == Material.water)
|
||||
{
|
||||
--itemStackIn.stackSize;
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
|
||||
if (itemStackIn.stackSize <= 0)
|
||||
{
|
||||
return new ItemStack(Items.potion);
|
||||
}
|
||||
|
||||
if (!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.potion)))
|
||||
{
|
||||
playerIn.dropPlayerItemWithRandomChoice(new ItemStack(Items.potion, 1, 0), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return itemStackIn;
|
||||
}
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(this.getTransform(), "potion_bottle_empty");
|
||||
}
|
||||
}
|
82
java/src/game/item/ItemGunBase.java
Executable file
82
java/src/game/item/ItemGunBase.java
Executable file
|
@ -0,0 +1,82 @@
|
|||
package game.item;
|
||||
|
||||
import game.enchantment.Enchantment;
|
||||
import game.enchantment.EnchantmentHelper;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.projectile.EntityBullet;
|
||||
import game.init.SoundEvent;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.world.World;
|
||||
|
||||
public abstract class ItemGunBase extends Item
|
||||
{
|
||||
public abstract ItemAmmo getAmmo();
|
||||
public abstract float getVelocity();
|
||||
|
||||
public ItemGunBase(int durability)
|
||||
{
|
||||
this.maxStackSize = 1;
|
||||
this.setMaxDamage(durability);
|
||||
this.setTab(CheatTab.tabCombat);
|
||||
}
|
||||
|
||||
public ItemAction getItemPosition(ItemStack stack)
|
||||
{
|
||||
return ItemAction.AIM;
|
||||
}
|
||||
|
||||
public ItemStack onItemRightClick(ItemStack stack, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
if(stack.getItemDamage() >= this.getMaxDamage())
|
||||
return stack;
|
||||
boolean flag = // playerIn.creative ||
|
||||
EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;
|
||||
if (flag || playerIn.inventory.hasItem(this.getAmmo()))
|
||||
{
|
||||
EntityBullet bullet = new EntityBullet(worldIn, playerIn, this.getVelocity());
|
||||
bullet.setDamage(this.getAmmo().getDamage(stack));
|
||||
|
||||
int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
|
||||
|
||||
if (j > 0)
|
||||
{
|
||||
bullet.setDamage(bullet.getDamage() + j);
|
||||
}
|
||||
|
||||
// int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
|
||||
//
|
||||
// if (k > 0)
|
||||
// {
|
||||
// entityarrow.setKnockbackStrength(k);
|
||||
// }
|
||||
|
||||
// if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0)
|
||||
// {
|
||||
// entityarrow.setFire(100);
|
||||
// }
|
||||
|
||||
stack.damageItem(1, playerIn);
|
||||
worldIn.playSoundAtEntity(playerIn, SoundEvent.EXPLODE_ALT, 1.0F, 1.5F);
|
||||
|
||||
if(!flag)
|
||||
playerIn.inventory.consumeInventoryItem(this.getAmmo());
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
|
||||
if (!worldIn.client)
|
||||
{
|
||||
worldIn.spawnEntityInWorld(bullet);
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.RANGED;
|
||||
}
|
||||
}
|
113
java/src/game/item/ItemHoe.java
Executable file
113
java/src/game/item/ItemHoe.java
Executable file
|
@ -0,0 +1,113 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.block.BlockDirt;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.init.ToolMaterial;
|
||||
import game.material.Material;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.State;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemHoe extends Item
|
||||
{
|
||||
protected ToolMaterial theToolMaterial;
|
||||
|
||||
public ItemHoe(ToolMaterial material)
|
||||
{
|
||||
this.theToolMaterial = material;
|
||||
this.maxStackSize = 1;
|
||||
this.setMaxDamage(material.getMaxUses());
|
||||
this.setTab(CheatTab.tabTools);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (!playerIn.canPlayerEdit(pos.offset(side), side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (side != Facing.DOWN && worldIn.getState(pos.up()).getBlock().getMaterial() == Material.air)
|
||||
{
|
||||
if (block == Blocks.grass)
|
||||
{
|
||||
return this.useHoe(stack, playerIn, worldIn, pos, Blocks.farmland.getState());
|
||||
}
|
||||
|
||||
if (block == Blocks.dirt)
|
||||
{
|
||||
switch ((BlockDirt.DirtType)iblockstate.getValue(BlockDirt.VARIANT))
|
||||
{
|
||||
case DIRT:
|
||||
return this.useHoe(stack, playerIn, worldIn, pos, Blocks.farmland.getState());
|
||||
|
||||
case COARSE_DIRT:
|
||||
return this.useHoe(stack, playerIn, worldIn, pos, Blocks.dirt.getState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.DIRT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean useHoe(ItemStack stack, EntityNPC player, World worldIn, BlockPos target, State newState)
|
||||
{
|
||||
if(newState.getBlock().sound.getStepSound() != null)
|
||||
worldIn.playSound(newState.getBlock().sound.getStepSound(), (double)((float)target.getX() + 0.5F), (double)((float)target.getY() + 0.5F), (double)((float)target.getZ() + 0.5F), (newState.getBlock().sound.getVolume() + 1.0F) / 2.0F, newState.getBlock().sound.getFrequency() * 0.8F);
|
||||
|
||||
if (worldIn.client)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
worldIn.setState(target, newState);
|
||||
stack.damageItem(1, player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Returns True is the item is renderer in full 3D when hold.
|
||||
// */
|
||||
// public boolean isFull3D()
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Returns the name of the material this tool is made from as it is declared in EnumToolMaterial (meaning diamond
|
||||
// * would return "EMERALD")
|
||||
// */
|
||||
// public String getMaterialName()
|
||||
// {
|
||||
// return this.theToolMaterial.toString();
|
||||
// }
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return this.theToolMaterial.isMagnetic();
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.TOOL;
|
||||
}
|
||||
|
||||
public ToolMaterial getToolMaterial()
|
||||
{
|
||||
return this.theToolMaterial;
|
||||
}
|
||||
}
|
19
java/src/game/item/ItemHorseArmor.java
Executable file
19
java/src/game/item/ItemHorseArmor.java
Executable file
|
@ -0,0 +1,19 @@
|
|||
package game.item;
|
||||
|
||||
import game.init.ToolMaterial;
|
||||
|
||||
public class ItemHorseArmor extends Item {
|
||||
private final ToolMaterial material;
|
||||
private final String texture;
|
||||
|
||||
public ItemHorseArmor(ToolMaterial material, String texture) {
|
||||
this.material = material;
|
||||
this.texture = texture;
|
||||
this.setMaxStackSize(1);
|
||||
this.setTab(CheatTab.tabCombat);
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return this.material.isMagnetic();
|
||||
}
|
||||
}
|
13
java/src/game/item/ItemHugeMushroom.java
Executable file
13
java/src/game/item/ItemHugeMushroom.java
Executable file
|
@ -0,0 +1,13 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
|
||||
public class ItemHugeMushroom extends ItemBlock {
|
||||
public ItemHugeMushroom(Block block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
public int getMetadata(int damage) {
|
||||
return 14;
|
||||
}
|
||||
}
|
26
java/src/game/item/ItemInfoWand.java
Executable file
26
java/src/game/item/ItemInfoWand.java
Executable file
|
@ -0,0 +1,26 @@
|
|||
package game.item;
|
||||
|
||||
import game.biome.Biome;
|
||||
import game.color.TextColor;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Vec3;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public class ItemInfoWand extends ItemWand {
|
||||
public ItemInfoWand() {
|
||||
this.setColor(TextColor.BLUE);
|
||||
}
|
||||
|
||||
public void onUse(ItemStack stack, EntityNPC player, WorldServer world, Vec3 vec)
|
||||
{
|
||||
Biome biome = world.getBiomeGenForCoords(new BlockPos(vec.xCoord, 0, vec.zCoord));
|
||||
player.connection.addFeed(TextColor.NEON + "* Position bei Level %d: %.3f %.3f %.3f, %s [%d], %.2f °C", world.dimension.getDimensionId(),
|
||||
vec.xCoord, vec.yCoord, vec.zCoord,
|
||||
biome.display, biome.id, world.getTemperatureC(new BlockPos(vec)));
|
||||
}
|
||||
|
||||
public int getRange(ItemStack stack, EntityNPC player) {
|
||||
return 250;
|
||||
}
|
||||
}
|
9
java/src/game/item/ItemKey.java
Executable file
9
java/src/game/item/ItemKey.java
Executable file
|
@ -0,0 +1,9 @@
|
|||
package game.item;
|
||||
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
|
||||
public class ItemKey extends ItemMagnetic {
|
||||
public Transforms getTransform() {
|
||||
return Transforms.KEY;
|
||||
}
|
||||
}
|
70
java/src/game/item/ItemLead.java
Executable file
70
java/src/game/item/ItemLead.java
Executable file
|
@ -0,0 +1,70 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.block.BlockFence;
|
||||
import game.entity.item.EntityLeashKnot;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.world.BlockPos;
|
||||
import game.world.BoundingBox;
|
||||
import game.world.Facing;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemLead extends Item
|
||||
{
|
||||
public ItemLead()
|
||||
{
|
||||
this.setTab(CheatTab.tabTools);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
Block block = worldIn.getState(pos).getBlock();
|
||||
|
||||
if (block instanceof BlockFence)
|
||||
{
|
||||
if (worldIn.client)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
attachToFence(playerIn, worldIn, pos);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean attachToFence(EntityNPC player, World worldIn, BlockPos fence)
|
||||
{
|
||||
EntityLeashKnot entityleashknot = EntityLeashKnot.getKnotForPosition(worldIn, fence);
|
||||
boolean flag = false;
|
||||
double d0 = 7.0D;
|
||||
int i = fence.getX();
|
||||
int j = fence.getY();
|
||||
int k = fence.getZ();
|
||||
|
||||
for (EntityLiving entityliving : worldIn.getEntitiesWithinAABB(EntityLiving.class, new BoundingBox((double)i - d0, (double)j - d0, (double)k - d0, (double)i + d0, (double)j + d0, (double)k + d0)))
|
||||
{
|
||||
if (entityliving.getLeashed() && entityliving.getLeashedTo() == player)
|
||||
{
|
||||
if (entityleashknot == null)
|
||||
{
|
||||
entityleashknot = EntityLeashKnot.createKnot(worldIn, fence);
|
||||
}
|
||||
|
||||
entityliving.setLeashedTo(entityleashknot, true);
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
}
|
45
java/src/game/item/ItemLeaves.java
Executable file
45
java/src/game/item/ItemLeaves.java
Executable file
|
@ -0,0 +1,45 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.BlockLeaves;
|
||||
import game.block.LeavesType;
|
||||
|
||||
public class ItemLeaves extends ItemBlock
|
||||
{
|
||||
protected final BlockLeaves leaves;
|
||||
|
||||
public ItemLeaves(BlockLeaves block)
|
||||
{
|
||||
super(block);
|
||||
this.leaves = block;
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage | 8;
|
||||
}
|
||||
|
||||
public int getColorFromItemStack(ItemStack stack, int renderPass)
|
||||
{
|
||||
return this.leaves.getRenderColor(this.leaves.getStateFromMeta(stack.getMetadata()));
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
// * different names based on their damage or NBT.
|
||||
// */
|
||||
// public String getUnlocalizedName(ItemStack stack)
|
||||
// {
|
||||
// return super.getUnlocalizedName() + "." + this.leaves.getWoodType().getUnlocalizedName();
|
||||
// }
|
||||
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
return this.block.getDisplay() + " (" + LeavesType.getById(stack.getMetadata()).getDisplayName() + ")";
|
||||
}
|
||||
}
|
26
java/src/game/item/ItemLightning.java
Executable file
26
java/src/game/item/ItemLightning.java
Executable file
|
@ -0,0 +1,26 @@
|
|||
package game.item;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.world.Vec3;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public class ItemLightning extends ItemWand {
|
||||
public ItemLightning() {
|
||||
this.setColor(TextColor.NEON);
|
||||
}
|
||||
|
||||
public void onUse(ItemStack stack, EntityNPC player, WorldServer world, Vec3 vec)
|
||||
{
|
||||
if(player.useMana(5))
|
||||
world.strikeLightning(vec.xCoord - 0.5, vec.yCoord, vec.zCoord - 0.5, 0x532380, 230, true, player);
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getRange(ItemStack stack, EntityNPC player) {
|
||||
return 100;
|
||||
}
|
||||
}
|
68
java/src/game/item/ItemLilyPad.java
Executable file
68
java/src/game/item/ItemLilyPad.java
Executable file
|
@ -0,0 +1,68 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.block.BlockDirectional;
|
||||
import game.block.BlockLiquid;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.world.BlockPos;
|
||||
import game.world.HitPosition;
|
||||
import game.world.State;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemLilyPad extends ItemColored
|
||||
{
|
||||
public ItemLilyPad(Block block)
|
||||
{
|
||||
super(block, false, "");
|
||||
}
|
||||
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
HitPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true);
|
||||
|
||||
if (movingobjectposition == null)
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (movingobjectposition.type == HitPosition.ObjectType.BLOCK)
|
||||
{
|
||||
BlockPos blockpos = movingobjectposition.block;
|
||||
|
||||
if (!World.isValidXZ(blockpos))
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.side), movingobjectposition.side, itemStackIn))
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
BlockPos blockpos1 = blockpos.up();
|
||||
State iblockstate = worldIn.getState(blockpos);
|
||||
|
||||
if (iblockstate.getBlock().getMaterial().isColdLiquid() && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.isAirBlock(blockpos1))
|
||||
{
|
||||
worldIn.setState(blockpos1, Blocks.waterlily.getState().withProperty(BlockDirectional.FACING, playerIn.getHorizontalFacing().getOpposite()));
|
||||
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--itemStackIn.stackSize;
|
||||
// }
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
}
|
||||
}
|
||||
|
||||
return itemStackIn;
|
||||
}
|
||||
}
|
||||
|
||||
public int getColorFromItemStack(ItemStack stack, int renderPass)
|
||||
{
|
||||
return Blocks.waterlily.getRenderColor(Blocks.waterlily.getStateFromMeta(stack.getMetadata()));
|
||||
}
|
||||
}
|
68
java/src/game/item/ItemMagnet.java
Executable file
68
java/src/game/item/ItemMagnet.java
Executable file
|
@ -0,0 +1,68 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import game.entity.Entity;
|
||||
import game.entity.animal.EntityChicken;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.world.BoundingBox;
|
||||
import game.world.Vec3;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemMagnet extends Item {
|
||||
private final boolean chicken;
|
||||
|
||||
public <T extends Entity> ItemMagnet(boolean chicken) {
|
||||
this.setTab(CheatTab.tabTools);
|
||||
this.setMaxStackSize(1);
|
||||
this.chicken = chicken;
|
||||
}
|
||||
|
||||
// public boolean isFull3D() {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// public boolean shouldRotateAroundWhenRendering() {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn) {
|
||||
float speed = 1.0f;
|
||||
if(!worldIn.client) {
|
||||
List<Entity> list = worldIn
|
||||
.getEntitiesWithinAABB(this.chicken ? EntityChicken.class : Entity.class,
|
||||
new BoundingBox(playerIn.posX - 40.0f, playerIn.posY + playerIn.getEyeHeight() - 40.0f, playerIn.posZ - 40.0f,
|
||||
playerIn.posX + 40.0f, playerIn.posY + playerIn.getEyeHeight() + 40.0f, playerIn.posZ + 40.0f),
|
||||
new Predicate<Entity>() {
|
||||
public boolean test(Entity entity) {
|
||||
return (ItemMagnet.this.chicken || /* ? !((EntityLiving)entity).isAIDisabled() : */ entity.isMagnetic())
|
||||
&& entity.getDistanceToEntity(playerIn) <= 38.0f;
|
||||
}
|
||||
});
|
||||
for(Entity entity : list) {
|
||||
if(entity.getDistance(playerIn.posX, playerIn.posY + playerIn.getEyeHeight(), playerIn.posZ) <= 2.0f) {
|
||||
entity.motionX *= 0.1f;
|
||||
entity.motionY *= 0.1f;
|
||||
entity.motionZ *= 0.1f;
|
||||
}
|
||||
else {
|
||||
Vec3 vec = new Vec3(playerIn.posX - entity.posX, playerIn.posY - entity.posY, playerIn.posZ - entity.posZ);
|
||||
vec = vec.normalize();
|
||||
entity.addVelocity(vec.xCoord * speed, vec.yCoord * speed, vec.zCoord * speed);
|
||||
}
|
||||
}
|
||||
}
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.TOOL_FLIP;
|
||||
}
|
||||
}
|
7
java/src/game/item/ItemMagnetic.java
Executable file
7
java/src/game/item/ItemMagnetic.java
Executable file
|
@ -0,0 +1,7 @@
|
|||
package game.item;
|
||||
|
||||
public class ItemMagnetic extends Item {
|
||||
public boolean isMagnetic() {
|
||||
return true;
|
||||
}
|
||||
}
|
53
java/src/game/item/ItemMetal.java
Executable file
53
java/src/game/item/ItemMetal.java
Executable file
|
@ -0,0 +1,53 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import game.collect.Sets;
|
||||
import game.color.TextColor;
|
||||
import game.entity.attributes.Attribute;
|
||||
import game.entity.attributes.AttributeModifier;
|
||||
import game.entity.attributes.Attributes;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.MetalType;
|
||||
|
||||
public class ItemMetal extends Item {
|
||||
private final MetalType metal;
|
||||
|
||||
public ItemMetal(MetalType metal) {
|
||||
this.metal = metal;
|
||||
if(this.metal.radioactivity > 0.0f)
|
||||
this.setColor(TextColor.GREEN);
|
||||
}
|
||||
|
||||
public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip)
|
||||
{
|
||||
tooltip.add(this.metal.formatSymbol());
|
||||
if(this.metal.radioactivity > 0.0f) {
|
||||
tooltip.add(this.metal.formatRadioactivity());
|
||||
}
|
||||
tooltip.add(this.metal.formatRarity());
|
||||
}
|
||||
|
||||
// public ChatFormat getColor(ItemStack stack)
|
||||
// {
|
||||
// return this.metal.radioactivity > 0.0f ? ChatFormat.GREEN : super.getColor(stack);
|
||||
// }
|
||||
|
||||
public Map<Attribute, Set<AttributeModifier>> getItemInventoryModifiers()
|
||||
{
|
||||
Map<Attribute, Set<AttributeModifier>> multimap = super.getItemInventoryModifiers();
|
||||
if(this.metal.radioactivity > 0.0f)
|
||||
multimap.put(Attributes.RADIATION, Sets.newHashSet(new AttributeModifier(Attributes.ITEM_VAL_ID, "Metal modifier", (double)this.metal.radioactivity * 4.0, false, true, true)));
|
||||
return multimap;
|
||||
}
|
||||
|
||||
public float getRadiation(ItemStack stack) {
|
||||
return this.metal.radioactivity * 0.25f * (float)stack.stackSize;
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return this.metal.isMagnetic();
|
||||
}
|
||||
}
|
57
java/src/game/item/ItemMetalBlock.java
Executable file
57
java/src/game/item/ItemMetalBlock.java
Executable file
|
@ -0,0 +1,57 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import game.block.Block;
|
||||
import game.collect.Sets;
|
||||
import game.color.TextColor;
|
||||
import game.entity.attributes.Attribute;
|
||||
import game.entity.attributes.AttributeModifier;
|
||||
import game.entity.attributes.Attributes;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.MetalType;
|
||||
|
||||
public class ItemMetalBlock extends ItemBlock {
|
||||
private final MetalType metal;
|
||||
private final boolean ore;
|
||||
|
||||
public ItemMetalBlock(Block block, MetalType metal, boolean ore) {
|
||||
super(block);
|
||||
this.metal = metal;
|
||||
this.ore = ore;
|
||||
if(this.metal.radioactivity > 0.0f)
|
||||
this.setColor(TextColor.GREEN);
|
||||
}
|
||||
|
||||
public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip)
|
||||
{
|
||||
tooltip.add(this.metal.formatSymbol());
|
||||
if(this.metal.radioactivity > 0.0f) {
|
||||
tooltip.add(this.metal.formatRadioactivity());
|
||||
}
|
||||
tooltip.add(this.metal.formatRarity());
|
||||
}
|
||||
|
||||
// public ChatFormat getColor(ItemStack stack)
|
||||
// {
|
||||
// return this.metal.radioactivity > 0.0f ? ChatFormat.GREEN : super.getColor(stack);
|
||||
// }
|
||||
|
||||
public Map<Attribute, Set<AttributeModifier>> getItemInventoryModifiers()
|
||||
{
|
||||
Map<Attribute, Set<AttributeModifier>> multimap = super.getItemInventoryModifiers();
|
||||
if(this.metal.radioactivity > 0.0f)
|
||||
multimap.put(Attributes.RADIATION, Sets.newHashSet(new AttributeModifier(Attributes.ITEM_VAL_ID, "Metal modifier", (double)this.metal.radioactivity * 4.0 * (this.ore ? 2.0 : 9.0), false, true, true)));
|
||||
return multimap;
|
||||
}
|
||||
|
||||
public float getRadiation(ItemStack stack) {
|
||||
return this.metal.radioactivity * (this.ore ? 0.5f : 2.0f) * (float)stack.stackSize;
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return this.metal.isMagnetic();
|
||||
}
|
||||
}
|
144
java/src/game/item/ItemMinecart.java
Executable file
144
java/src/game/item/ItemMinecart.java
Executable file
|
@ -0,0 +1,144 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.BlockDispenser;
|
||||
import game.block.BlockRailBase;
|
||||
import game.dispenser.BehaviorDefaultDispenseItem;
|
||||
import game.dispenser.IBehaviorDispenseItem;
|
||||
import game.dispenser.IBlockSource;
|
||||
import game.entity.item.EntityCart;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.DispenserRegistry;
|
||||
import game.material.Material;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.State;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemMinecart extends Item
|
||||
{
|
||||
private static final IBehaviorDispenseItem dispenserMinecartBehavior = new BehaviorDefaultDispenseItem()
|
||||
{
|
||||
private final BehaviorDefaultDispenseItem behaviourDefaultDispenseItem = new BehaviorDefaultDispenseItem();
|
||||
public ItemStack dispenseStack(IBlockSource source, ItemStack stack)
|
||||
{
|
||||
Facing enumfacing = BlockDispenser.getFacing(source.getBlockMetadata());
|
||||
World world = source.getWorld();
|
||||
double d0 = source.getX() + (double)enumfacing.getFrontOffsetX() * 1.125D;
|
||||
double d1 = Math.floor(source.getY()) + (double)enumfacing.getFrontOffsetY();
|
||||
double d2 = source.getZ() + (double)enumfacing.getFrontOffsetZ() * 1.125D;
|
||||
BlockPos blockpos = source.getBlockPos().offset(enumfacing);
|
||||
State iblockstate = world.getState(blockpos);
|
||||
BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = iblockstate.getBlock() instanceof BlockRailBase ? (BlockRailBase.EnumRailDirection)iblockstate.getValue(((BlockRailBase)iblockstate.getBlock()).getShapeProperty()) : BlockRailBase.EnumRailDirection.NORTH_SOUTH;
|
||||
double d3;
|
||||
|
||||
if (BlockRailBase.isRailBlock(iblockstate))
|
||||
{
|
||||
if (blockrailbase$enumraildirection.isAscending())
|
||||
{
|
||||
d3 = 0.6D;
|
||||
}
|
||||
else
|
||||
{
|
||||
d3 = 0.1D;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iblockstate.getBlock().getMaterial() != Material.air || !BlockRailBase.isRailBlock(world.getState(blockpos.down())))
|
||||
{
|
||||
return this.behaviourDefaultDispenseItem.dispense(source, stack);
|
||||
}
|
||||
|
||||
State iblockstate1 = world.getState(blockpos.down());
|
||||
BlockRailBase.EnumRailDirection blockrailbase$enumraildirection1 = iblockstate1.getBlock() instanceof BlockRailBase ? (BlockRailBase.EnumRailDirection)iblockstate1.getValue(((BlockRailBase)iblockstate1.getBlock()).getShapeProperty()) : BlockRailBase.EnumRailDirection.NORTH_SOUTH;
|
||||
|
||||
if (enumfacing != Facing.DOWN && blockrailbase$enumraildirection1.isAscending())
|
||||
{
|
||||
d3 = -0.4D;
|
||||
}
|
||||
else
|
||||
{
|
||||
d3 = -0.9D;
|
||||
}
|
||||
}
|
||||
|
||||
EntityCart entityminecart = EntityCart.getMinecart(world, d0, d1 + d3, d2, ((ItemMinecart)stack.getItem()).minecartType);
|
||||
|
||||
if (stack.hasDisplayName())
|
||||
{
|
||||
entityminecart.setCustomNameTag(stack.getDisplayName());
|
||||
}
|
||||
|
||||
world.spawnEntityInWorld(entityminecart);
|
||||
stack.splitStack(1);
|
||||
return stack;
|
||||
}
|
||||
protected void playDispenseSound(IBlockSource source)
|
||||
{
|
||||
source.getWorld().playAuxSFX(1000, source.getBlockPos(), 0);
|
||||
}
|
||||
};
|
||||
private final EntityCart.EnumMinecartType minecartType;
|
||||
|
||||
public ItemMinecart(EntityCart.EnumMinecartType type)
|
||||
{
|
||||
this.maxStackSize = 1;
|
||||
this.minecartType = type;
|
||||
this.setTab(CheatTab.tabSpawners);
|
||||
// if(type != EntityMinecart.EnumMinecartType.COMMAND_BLOCK)
|
||||
DispenserRegistry.REGISTRY.putObject(this, dispenserMinecartBehavior);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
|
||||
if (BlockRailBase.isRailBlock(iblockstate))
|
||||
{
|
||||
if (!worldIn.client)
|
||||
{
|
||||
// EnumMinecartType type = this.minecartType;
|
||||
// if(this.minecartType == EnumMinecartType.COMMAND_BLOCK && !((EntityNPCMP)playerIn).canUse(Permissions.CMDBLOCK)) {
|
||||
// type = EnumMinecartType.RIDEABLE;
|
||||
// EntityItem entityitem = playerIn.dropPlayerItemWithRandomChoice(new ItemStack(Blocks.command_block), false);
|
||||
// if(entityitem != null) {
|
||||
// entityitem.setNoPickupDelay();
|
||||
// entityitem.setOwner(playerIn.getUser());
|
||||
// }
|
||||
// }
|
||||
BlockRailBase.EnumRailDirection blockrailbase$enumraildirection = iblockstate.getBlock() instanceof BlockRailBase ? (BlockRailBase.EnumRailDirection)iblockstate.getValue(((BlockRailBase)iblockstate.getBlock()).getShapeProperty()) : BlockRailBase.EnumRailDirection.NORTH_SOUTH;
|
||||
double d0 = 0.0D;
|
||||
|
||||
if (blockrailbase$enumraildirection.isAscending())
|
||||
{
|
||||
d0 = 0.5D;
|
||||
}
|
||||
|
||||
EntityCart entityminecart = EntityCart.getMinecart(worldIn, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.0625D + d0, (double)pos.getZ() + 0.5D, this.minecartType);
|
||||
|
||||
if (stack.hasDisplayName())
|
||||
{
|
||||
entityminecart.setCustomNameTag(stack.getDisplayName());
|
||||
}
|
||||
|
||||
worldIn.spawnEntityInWorld(entityminecart);
|
||||
// if(this.minecartType == EnumMinecartType.COMMAND_BLOCK)
|
||||
// ((EntityMinecartCommandBlock)entityminecart).getCommandBlockLogic().setEnabled(((EntityNPCMP)playerIn).canUse(Permissions.CMDBLOCK));
|
||||
}
|
||||
|
||||
--stack.stackSize;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return true;
|
||||
}
|
||||
}
|
271
java/src/game/item/ItemMonsterPlacer.java
Executable file
271
java/src/game/item/ItemMonsterPlacer.java
Executable file
|
@ -0,0 +1,271 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.ExtMath;
|
||||
import game.block.BlockFence;
|
||||
import game.block.BlockLiquid;
|
||||
import game.color.TextColor;
|
||||
import game.dimension.Dimension;
|
||||
import game.entity.Entity;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.init.Blocks;
|
||||
import game.init.EntityEggInfo;
|
||||
import game.init.EntityRegistry;
|
||||
import game.init.UniverseRegistry;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.tileentity.TileEntity;
|
||||
import game.tileentity.TileEntityMobSpawner;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.HitPosition;
|
||||
import game.world.State;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemMonsterPlacer extends Item
|
||||
{
|
||||
private final String entityId;
|
||||
|
||||
public ItemMonsterPlacer(String entityId)
|
||||
{
|
||||
// this.setHasSubtypes(true);
|
||||
this.setTab(CheatTab.tabSpawners);
|
||||
this.entityId = entityId;
|
||||
}
|
||||
|
||||
public String getSpawnedId() {
|
||||
return this.entityId;
|
||||
}
|
||||
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
String s = "Erschaffe";
|
||||
String s1 = this.entityId;
|
||||
|
||||
if (s1 != null)
|
||||
{
|
||||
s = s + " " + EntityRegistry.getEntityName(s1);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public int getColorFromItemStack(ItemStack stack, int renderPass)
|
||||
{
|
||||
EntityEggInfo egg = EntityRegistry.SPAWN_EGGS.get(this.entityId);
|
||||
return egg != null ? (renderPass == 0 ? egg.primaryColor : egg.secondaryColor) : 16777215;
|
||||
}
|
||||
|
||||
public void addInformation(ItemStack stack, EntityNPC player, List<String> tooltip) {
|
||||
EntityEggInfo egg = EntityRegistry.SPAWN_EGGS.get(this.entityId);
|
||||
if(egg != null) {
|
||||
Dimension dim = egg.origin == null ? null : UniverseRegistry.getDimension(egg.origin);
|
||||
tooltip.add(TextColor.ORANGE + "Herkunft: " + (dim == null ? "???" : dim.getFormattedName(false)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (worldIn.client)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (!playerIn.canPlayerEdit(pos.offset(side), side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
|
||||
if (iblockstate.getBlock() == Blocks.mob_spawner)
|
||||
{
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentity instanceof TileEntityMobSpawner)
|
||||
{
|
||||
// MobSpawnerBaseLogic mobspawnerbaselogic = ((TileEntityMobSpawner)tileentity).getSpawnerBaseLogic();
|
||||
((TileEntityMobSpawner)tileentity).setEntityName(this.entityId);
|
||||
tileentity.markDirty();
|
||||
worldIn.markBlockForUpdate(pos);
|
||||
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--stack.stackSize;
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
pos = pos.offset(side);
|
||||
double d0 = 0.0D;
|
||||
|
||||
if (side == Facing.UP && iblockstate.getBlock() instanceof BlockFence)
|
||||
{
|
||||
d0 = 0.5D;
|
||||
}
|
||||
|
||||
|
||||
int amount = Math.min(stack.stackSize, 128);
|
||||
for(int z = 0; z < amount; z++) {
|
||||
Entity entity = spawnCreature(worldIn, this.entityId, (double)pos.getX() + 0.5D, (double)pos.getY() + d0, (double)pos.getZ() + 0.5D);
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
// if (entity instanceof EntityLiving)
|
||||
// {
|
||||
// ((EntityLiving)entity).disableDespawn();
|
||||
// }
|
||||
|
||||
if (entity instanceof EntityLiving && stack.hasDisplayName())
|
||||
{
|
||||
entity.setCustomNameTag(stack.getDisplayName());
|
||||
}
|
||||
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--stack.stackSize;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
if (worldIn.client)
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
else
|
||||
{
|
||||
HitPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true);
|
||||
|
||||
if (movingobjectposition == null)
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (movingobjectposition.type == HitPosition.ObjectType.BLOCK)
|
||||
{
|
||||
BlockPos blockpos = movingobjectposition.block;
|
||||
|
||||
if (!World.isValidXZ(blockpos))
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
if (!playerIn.canPlayerEdit(blockpos, movingobjectposition.side, itemStackIn))
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
if (worldIn.getState(blockpos).getBlock() instanceof BlockLiquid)
|
||||
{
|
||||
int amount = Math.min(itemStackIn.stackSize, 128);
|
||||
for(int z = 0; z < amount; z++) {
|
||||
Entity entity = spawnCreature(worldIn, this.entityId, (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D);
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
// if (entity instanceof EntityLiving)
|
||||
// {
|
||||
// ((EntityLiving)entity).disableDespawn();
|
||||
// }
|
||||
|
||||
if (entity instanceof EntityLiving && itemStackIn.hasDisplayName())
|
||||
{
|
||||
((EntityLiving)entity).setCustomNameTag(itemStackIn.getDisplayName());
|
||||
}
|
||||
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--itemStackIn.stackSize;
|
||||
// }
|
||||
|
||||
// if(z == 0)
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return itemStackIn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns the creature specified by the egg's type in the location specified by the last three parameters.
|
||||
* Parameters: world, entityID, x, y, z.
|
||||
*/
|
||||
public static Entity spawnCreature(World worldIn, String entityID, double x, double y, double z)
|
||||
{
|
||||
if (!EntityRegistry.SPAWN_EGGS.containsKey(entityID))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Entity entity = null;
|
||||
|
||||
for (int i = 0; i < 1; ++i)
|
||||
{
|
||||
entity = EntityRegistry.createEntityByName(entityID, worldIn);
|
||||
|
||||
if (entity instanceof EntityLiving)
|
||||
{
|
||||
EntityLiving entityliving = (EntityLiving)entity;
|
||||
entity.setLocationAndAngles(x, y, z, ExtMath.wrapf(worldIn.rand.floatv() * 360.0F), 0.0F);
|
||||
entityliving.headYaw = entityliving.rotYaw;
|
||||
entityliving.yawOffset = entityliving.rotYaw;
|
||||
entityliving.onInitialSpawn(null);
|
||||
worldIn.spawnEntityInWorld(entity);
|
||||
entityliving.playLivingSound();
|
||||
}
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
// */
|
||||
// public void getSubItems(Item itemIn, CreativeTab tab, List<ItemStack> subItems)
|
||||
// {
|
||||
// for (EntityEggInfo entitylist$entityegginfo : EntityRegistry.SPAWN_EGGS.values())
|
||||
// {
|
||||
// subItems.add(new ItemStack(itemIn, 1, entitylist$entityegginfo.spawnedID));
|
||||
// }
|
||||
// }
|
||||
|
||||
// public ItemMeshDefinition getMesher() {
|
||||
// return new ItemMeshDefinition()
|
||||
// {
|
||||
// public String getModelLocation(ItemStack stack)
|
||||
// {
|
||||
// return "item/spawn_egg#0" + '#' + "inventory";
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
|
||||
// public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
|
||||
// subItems.add(new ItemStack(itemIn, 1, 0));
|
||||
// }
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(this.getTransform(), "spawn_egg", "spawn_egg_overlay");
|
||||
}
|
||||
}
|
61
java/src/game/item/ItemMultiTexture.java
Executable file
61
java/src/game/item/ItemMultiTexture.java
Executable file
|
@ -0,0 +1,61 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import game.block.Block;
|
||||
|
||||
public class ItemMultiTexture extends ItemBlock
|
||||
{
|
||||
protected final Block theBlock;
|
||||
protected final Function<ItemStack, String> nameFunction;
|
||||
|
||||
public ItemMultiTexture(Block block, Block block2, boolean flatTexture, Function<ItemStack, String> nameFunction)
|
||||
{
|
||||
super(block, flatTexture ? "" : null);
|
||||
this.theBlock = block2;
|
||||
this.nameFunction = nameFunction;
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
public ItemMultiTexture(Block block, Block block2, Function<ItemStack, String> nameFunction)
|
||||
{
|
||||
this(block, block2, false, nameFunction);
|
||||
}
|
||||
|
||||
public ItemMultiTexture(Block block, Block block2, final String[] namesByMeta)
|
||||
{
|
||||
this(block, block2, false, new Function<ItemStack, String>()
|
||||
{
|
||||
public String apply(ItemStack p_apply_1_)
|
||||
{
|
||||
int i = p_apply_1_.getMetadata();
|
||||
|
||||
if (i < 0 || i >= namesByMeta.length)
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
|
||||
return namesByMeta[i];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
* different names based on their damage or NBT.
|
||||
*/
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
return this.nameFunction.apply(stack);
|
||||
}
|
||||
}
|
35
java/src/game/item/ItemNameTag.java
Executable file
35
java/src/game/item/ItemNameTag.java
Executable file
|
@ -0,0 +1,35 @@
|
|||
package game.item;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.types.EntityLiving;
|
||||
|
||||
public class ItemNameTag extends Item
|
||||
{
|
||||
public ItemNameTag()
|
||||
{
|
||||
this.setTab(CheatTab.tabTools);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the item can be used on the given entity, e.g. shears on sheep.
|
||||
*/
|
||||
public boolean itemInteractionForEntity(ItemStack stack, EntityNPC playerIn, EntityLiving target)
|
||||
{
|
||||
if (!stack.hasDisplayName())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (target instanceof EntityLiving && !(target.isPlayer()))
|
||||
{
|
||||
EntityLiving entityliving = (EntityLiving)target;
|
||||
entityliving.setCustomNameTag(stack.getDisplayName());
|
||||
// entityliving.disableDespawn();
|
||||
--stack.stackSize;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.itemInteractionForEntity(stack, playerIn, target);
|
||||
}
|
||||
}
|
||||
}
|
207
java/src/game/item/ItemNpcSpawner.java
Executable file
207
java/src/game/item/ItemNpcSpawner.java
Executable file
|
@ -0,0 +1,207 @@
|
|||
package game.item;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
import game.ExtMath;
|
||||
import game.block.BlockFence;
|
||||
import game.block.BlockLiquid;
|
||||
import game.color.TextColor;
|
||||
import game.dimension.Dimension;
|
||||
import game.entity.Entity;
|
||||
import game.entity.npc.CharacterInfo;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.npc.EntityNPC.CharacterTypeData;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.init.EntityRegistry;
|
||||
import game.init.UniverseRegistry;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.HitPosition;
|
||||
import game.world.State;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemNpcSpawner extends Item
|
||||
{
|
||||
private final CharacterInfo spawned;
|
||||
|
||||
public ItemNpcSpawner(CharacterInfo spawned)
|
||||
{
|
||||
// this.setHasSubtypes(true);
|
||||
this.setTab(CheatTab.tabSpawners);
|
||||
this.spawned = spawned;
|
||||
}
|
||||
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
String item = "Erschaffe";
|
||||
CharacterInfo info = this.spawned; // SpeciesRegistry.CHARACTERS.get(stack.getMetadata() % SpeciesRegistry.CHARACTERS.size());
|
||||
String species = EntityRegistry.getEntityName(info.species.id);
|
||||
if(info.species.prefix && info.spclass != null && info.spclass.type != null)
|
||||
species = info.spclass.type.toString();
|
||||
String character = info.name;
|
||||
item = item + " " + species + (character.isEmpty() ? "" : (" " + character));
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public int getColorFromItemStack(ItemStack stack, int renderPass)
|
||||
{
|
||||
return renderPass == 0 ? this.spawned.color1 : this.spawned.color2;
|
||||
}
|
||||
|
||||
public void addInformation(ItemStack stack, EntityNPC player, List<String> tooltip) {
|
||||
Dimension dim = this.spawned.species.origin == null ? null : UniverseRegistry.getDimension(this.spawned.species.origin);
|
||||
tooltip.add(TextColor.ORANGE + "Herkunft: " + (dim == null ? "???" : dim.getFormattedName(false)));
|
||||
}
|
||||
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (worldIn.client)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (!playerIn.canPlayerEdit(pos.offset(side), side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
|
||||
pos = pos.offset(side);
|
||||
double d0 = 0.0D;
|
||||
|
||||
if (side == Facing.UP && iblockstate.getBlock() instanceof BlockFence)
|
||||
{
|
||||
d0 = 0.5D;
|
||||
}
|
||||
|
||||
int amount = Math.min(stack.stackSize, 128);
|
||||
for(int z = 0; z < amount; z++) {
|
||||
Entity entity = spawnNpc(worldIn, this.spawned, (double)pos.getX() + 0.5D, (double)pos.getY() + d0, (double)pos.getZ() + 0.5D);
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
if (stack.hasDisplayName())
|
||||
{
|
||||
entity.setCustomNameTag(stack.getDisplayName());
|
||||
}
|
||||
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--stack.stackSize;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
if (worldIn.client)
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
else
|
||||
{
|
||||
HitPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true);
|
||||
|
||||
if (movingobjectposition == null)
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (movingobjectposition.type == HitPosition.ObjectType.BLOCK)
|
||||
{
|
||||
BlockPos blockpos = movingobjectposition.block;
|
||||
|
||||
if (!World.isValidXZ(blockpos))
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
if (!playerIn.canPlayerEdit(blockpos, movingobjectposition.side, itemStackIn))
|
||||
{
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
if (worldIn.getState(blockpos).getBlock() instanceof BlockLiquid)
|
||||
{
|
||||
int amount = Math.min(itemStackIn.stackSize, 128);
|
||||
for(int z = 0; z < amount; z++) {
|
||||
Entity entity = spawnNpc(worldIn, this.spawned, (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D);
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
if (itemStackIn.hasDisplayName())
|
||||
{
|
||||
((EntityLiving)entity).setCustomNameTag(itemStackIn.getDisplayName());
|
||||
}
|
||||
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--itemStackIn.stackSize;
|
||||
// }
|
||||
|
||||
// if(z == 0)
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return itemStackIn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Entity spawnNpc(World worldIn, CharacterInfo character, double x, double y, double z)
|
||||
{
|
||||
// CharacterInfo character = SpeciesRegistry.CHARACTERS.get(entityID % SpeciesRegistry.CHARACTERS.size());
|
||||
EntityNPC entity;
|
||||
try {
|
||||
entity = character.species.clazz.getConstructor(World.class).newInstance(worldIn);
|
||||
}
|
||||
catch(InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
entity.setLocationAndAngles(x, y, z, ExtMath.wrapf(worldIn.rand.floatv() * 360.0F), 0.0F);
|
||||
entity.headYaw = entity.rotYaw;
|
||||
entity.yawOffset = entity.rotYaw;
|
||||
entity.onInitialSpawn(new CharacterTypeData(character));
|
||||
// entity.setFromInfo(character);
|
||||
worldIn.spawnEntityInWorld(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
// public void getSubItems(Item itemIn, CreativeTab tab, List<ItemStack> subItems)
|
||||
// {
|
||||
// for (int z = 0; z < SpeciesRegistry.CHARACTERS.size(); z++)
|
||||
// {
|
||||
// subItems.add(new ItemStack(itemIn, 1, z));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public ItemMeshDefinition getMesher() {
|
||||
// return new ItemMeshDefinition()
|
||||
// {
|
||||
// public String getModelLocation(ItemStack stack)
|
||||
// {
|
||||
// return "item/npc_spawner#0" + '#' + "inventory";
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
//
|
||||
// public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
|
||||
// subItems.add(new ItemStack(itemIn, 1, 0));
|
||||
// }
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(this.getTransform(), "npc_spawner", "npc_spawner_overlay");
|
||||
}
|
||||
}
|
9
java/src/game/item/ItemNugget.java
Executable file
9
java/src/game/item/ItemNugget.java
Executable file
|
@ -0,0 +1,9 @@
|
|||
package game.item;
|
||||
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
|
||||
public class ItemNugget extends Item {
|
||||
public Transforms getTransform() {
|
||||
return Transforms.NUGGET;
|
||||
}
|
||||
}
|
46
java/src/game/item/ItemPickaxe.java
Executable file
46
java/src/game/item/ItemPickaxe.java
Executable file
|
@ -0,0 +1,46 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.init.ToolMaterial;
|
||||
|
||||
public class ItemPickaxe extends ItemTool
|
||||
{
|
||||
// private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(new Block[] {
|
||||
// Blocks.activator_rail, Blocks.coal_ore, Blocks.cobblestone, Blocks.detector_rail, Blocks.diamond_block, Blocks.diamond_ore, Blocks.double_stone_slab,
|
||||
// Blocks.golden_rail, Blocks.gold_block, Blocks.gold_ore, Blocks.ice, Blocks.iron_block, Blocks.iron_ore, Blocks.lapis_block, Blocks.lapis_ore,
|
||||
// Blocks.lit_redstone_ore, Blocks.mossy_cobblestone, Blocks.netherrack, Blocks.packed_ice, Blocks.rail, Blocks.redstone_ore, Blocks.sandstone,
|
||||
// Blocks.red_sandstone, Blocks.stone, Blocks.stone_slab
|
||||
// });
|
||||
|
||||
public ItemPickaxe(ToolMaterial material)
|
||||
{
|
||||
super(2, material);
|
||||
}
|
||||
|
||||
public boolean canHarvestBlock(Block blockIn)
|
||||
{
|
||||
return blockIn.getMiningLevel() >= 0 && this.toolMaterial.getHarvestLevel() >= blockIn.getMiningLevel();
|
||||
// blockIn == Blocks.obsidian ? this.toolMaterial.getHarvestLevel() == 3 :
|
||||
// (blockIn != Blocks.diamond_block && blockIn != Blocks.diamond_ore ?
|
||||
// (blockIn != Blocks.emerald_ore && blockIn != Blocks.emerald_block ?
|
||||
// (blockIn != Blocks.gold_block && blockIn != Blocks.gold_ore ?
|
||||
// (blockIn != Blocks.iron_block && blockIn != Blocks.iron_ore ?
|
||||
// (blockIn != Blocks.lapis_block && blockIn != Blocks.lapis_ore ?
|
||||
// (blockIn != Blocks.redstone_ore && blockIn != Blocks.lit_redstone_ore ?
|
||||
// (blockIn.getMaterial() == Material.rock ? true :
|
||||
// (blockIn.getMaterial() == Material.iron ? true :
|
||||
// blockIn.getMaterial() == Material.anvil)) :
|
||||
// this.toolMaterial.getHarvestLevel() >= 2) :
|
||||
// this.toolMaterial.getHarvestLevel() >= 1) :
|
||||
// this.toolMaterial.getHarvestLevel() >= 1) :
|
||||
// this.toolMaterial.getHarvestLevel() >= 2) :
|
||||
// this.toolMaterial.getHarvestLevel() >= 2) :
|
||||
// this.toolMaterial.getHarvestLevel() >= 2);
|
||||
}
|
||||
|
||||
public boolean canUseOn(ItemStack stack, Block state)
|
||||
{
|
||||
return state.getMiningLevel() >= 0 /* state.getMaterial() != Material.iron && state.getMaterial() != Material.anvil && state.getMaterial() != Material.rock
|
||||
? super.getStrVsBlock(stack, state) */;
|
||||
}
|
||||
}
|
31
java/src/game/item/ItemPiston.java
Executable file
31
java/src/game/item/ItemPiston.java
Executable file
|
@ -0,0 +1,31 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.init.Blocks;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
|
||||
public class ItemPiston extends ItemBlock
|
||||
{
|
||||
public ItemPiston(Block block)
|
||||
{
|
||||
super(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(new ModelBlock("piston_side").add().nswe().d("piston_bottom").u("piston_top" + (this.block ==
|
||||
Blocks.sticky_piston ? "_sticky" : "")), this.getTransform());
|
||||
}
|
||||
}
|
445
java/src/game/item/ItemPotion.java
Executable file
445
java/src/game/item/ItemPotion.java
Executable file
|
@ -0,0 +1,445 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import game.collect.Maps;
|
||||
import game.collect.Sets;
|
||||
import game.color.TextColor;
|
||||
import game.entity.attributes.Attribute;
|
||||
import game.entity.attributes.AttributeModifier;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.projectile.EntityPotion;
|
||||
import game.init.Items;
|
||||
import game.init.SoundEvent;
|
||||
import game.potion.Potion;
|
||||
import game.potion.PotionEffect;
|
||||
import game.potion.PotionHelper;
|
||||
import game.renderer.ItemMeshDefinition;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemPotion extends Item
|
||||
{
|
||||
private Map<Integer, List<PotionEffect>> effectCache = Maps.<Integer, List<PotionEffect>>newHashMap();
|
||||
private static final Map<List<PotionEffect>, Integer> SUB_ITEMS_CACHE = Maps.<List<PotionEffect>, Integer>newLinkedHashMap();
|
||||
|
||||
public ItemPotion()
|
||||
{
|
||||
this.setMaxStackSize(1);
|
||||
this.setHasSubtypes(true);
|
||||
this.setMaxDamage(0);
|
||||
this.setTab(CheatTab.tabMagic);
|
||||
this.setColor(TextColor.ORK);
|
||||
}
|
||||
|
||||
public List<PotionEffect> getEffects(ItemStack stack)
|
||||
{
|
||||
// if (stack.hasTagCompound() && stack.getTagCompound().hasKey("CustomPotionEffects", 9))
|
||||
// {
|
||||
// List<PotionEffect> list1 = Lists.<PotionEffect>newArrayList();
|
||||
// NBTTagList nbttaglist = stack.getTagCompound().getTagList("CustomPotionEffects", 10);
|
||||
//
|
||||
// for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
// {
|
||||
// NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
|
||||
// PotionEffect potioneffect = PotionEffect.readCustomPotionEffectFromNBT(nbttagcompound);
|
||||
//
|
||||
// if (potioneffect != null)
|
||||
// {
|
||||
// list1.add(potioneffect);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return list1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
List<PotionEffect> list = (List)this.effectCache.get(Integer.valueOf(stack.getMetadata()));
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
list = PotionHelper.getPotionEffects(stack.getMetadata(), false);
|
||||
this.effectCache.put(Integer.valueOf(stack.getMetadata()), list);
|
||||
}
|
||||
|
||||
return list;
|
||||
// }
|
||||
}
|
||||
|
||||
public List<PotionEffect> getEffects(int meta)
|
||||
{
|
||||
List<PotionEffect> list = (List)this.effectCache.get(Integer.valueOf(meta));
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
list = PotionHelper.getPotionEffects(meta, false);
|
||||
this.effectCache.put(Integer.valueOf(meta), list);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
|
||||
* the Item before the action is complete.
|
||||
*/
|
||||
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--stack.stackSize;
|
||||
// }
|
||||
|
||||
if (!worldIn.client)
|
||||
{
|
||||
List<PotionEffect> list = this.getEffects(stack);
|
||||
|
||||
if (list != null)
|
||||
{
|
||||
for (PotionEffect potioneffect : list)
|
||||
{
|
||||
playerIn.addEffect(new PotionEffect(potioneffect));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
if (stack.stackSize <= 0)
|
||||
{
|
||||
return new ItemStack(Items.glass_bottle);
|
||||
}
|
||||
|
||||
playerIn.inventory.addItemStackToInventory(new ItemStack(Items.glass_bottle));
|
||||
// }
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long it takes to use or consume an item
|
||||
*/
|
||||
public int getMaxItemUseDuration(ItemStack stack)
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the action that specifies what animation to play when the items is being used
|
||||
*/
|
||||
public ItemAction getItemUseAction(ItemStack stack)
|
||||
{
|
||||
return ItemAction.DRINK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
if (isSplash(itemStackIn.getMetadata()))
|
||||
{
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--itemStackIn.stackSize;
|
||||
// }
|
||||
|
||||
worldIn.playSoundAtEntity(playerIn, SoundEvent.THROW, 0.5F, 0.4F / (itemRand.floatv() * 0.4F + 0.8F));
|
||||
|
||||
if (!worldIn.client)
|
||||
{
|
||||
worldIn.spawnEntityInWorld(new EntityPotion(worldIn, playerIn, itemStackIn));
|
||||
}
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return itemStackIn;
|
||||
}
|
||||
else
|
||||
{
|
||||
playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn));
|
||||
return itemStackIn;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns wether or not a potion is a throwable splash potion based on damage value
|
||||
*/
|
||||
public static boolean isSplash(int meta)
|
||||
{
|
||||
return (meta & 16384) != 0;
|
||||
}
|
||||
|
||||
public int getColorFromDamage(int meta)
|
||||
{
|
||||
return PotionHelper.getLiquidColor(meta);
|
||||
}
|
||||
|
||||
public int getColorFromItemStack(ItemStack stack, int renderPass)
|
||||
{
|
||||
return renderPass > 0 ? 16777215 : this.getColorFromDamage(stack.getMetadata());
|
||||
}
|
||||
|
||||
public boolean isEffectInstant(int meta)
|
||||
{
|
||||
List<PotionEffect> list = this.getEffects(meta);
|
||||
|
||||
if (list != null && !list.isEmpty())
|
||||
{
|
||||
for (PotionEffect potioneffect : list)
|
||||
{
|
||||
if (Potion.POTION_TYPES[potioneffect.getPotionID()].isInstant())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
if ((stack.getMetadata() & 16383) == 0)
|
||||
{
|
||||
return (isSplash(stack.getMetadata()) ? "Werfbare " : "") + "Wasserflasche";
|
||||
}
|
||||
else
|
||||
{
|
||||
String s = "";
|
||||
|
||||
if (isSplash(stack.getMetadata()))
|
||||
{
|
||||
s = "Werfbarer ";
|
||||
}
|
||||
|
||||
List<PotionEffect> list = Items.potion.getEffects(stack);
|
||||
|
||||
if (list != null && !list.isEmpty())
|
||||
{
|
||||
String s2 = ((PotionEffect)list.get(0)).getPotionName();
|
||||
// s2 = s2 + ".postfix";
|
||||
return s + s2.trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
String s1 = PotionHelper.getPotionPrefix(stack.getMetadata());
|
||||
return s1.trim() + " " + super.getDisplay(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* allows items to add custom lines of information to the mouseover description
|
||||
*/
|
||||
public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip)
|
||||
{
|
||||
if ((stack.getMetadata() & 16383) != 0)
|
||||
{
|
||||
List<PotionEffect> list = Items.potion.getEffects(stack);
|
||||
Map<Attribute, Set<AttributeModifier>> multimap = Maps.newHashMap();
|
||||
|
||||
if (list != null && !list.isEmpty())
|
||||
{
|
||||
for (PotionEffect potioneffect : list)
|
||||
{
|
||||
String s1 = potioneffect.getEffectName().trim();
|
||||
Potion potion = Potion.POTION_TYPES[potioneffect.getPotionID()];
|
||||
Map<Attribute, AttributeModifier> map = potion.getAttributeModifierMap();
|
||||
|
||||
if (map != null && map.size() > 0)
|
||||
{
|
||||
for (Entry<Attribute, AttributeModifier> entry : map.entrySet())
|
||||
{
|
||||
AttributeModifier attributemodifier = (AttributeModifier)entry.getValue();
|
||||
AttributeModifier attributemodifier1 = new AttributeModifier(attributemodifier.getName(), potion.getAttributeModifierAmount(potioneffect.getAmplifier(), attributemodifier), attributemodifier.isMultiplied());
|
||||
Set<AttributeModifier> set = multimap.get(entry.getKey());
|
||||
if(set == null)
|
||||
multimap.put(entry.getKey(), set = Sets.newHashSet());
|
||||
set.add(attributemodifier1);
|
||||
// multimap.put((Attribute)entry.getKey(), set);
|
||||
}
|
||||
}
|
||||
|
||||
s1 = s1 + PotionHelper.getPotionPotency(potioneffect.getAmplifier());
|
||||
// if (potioneffect.getAmplifier() >= 1 && potioneffect.getAmplifier() <= 9)
|
||||
// {
|
||||
// s1 = s1 + " " + Strs.get("potion.potency." + potioneffect.getAmplifier()).trim();
|
||||
// }
|
||||
// else if (potioneffect.getAmplifier() != 0)
|
||||
// {
|
||||
// s1 = s1 + " " + (potioneffect.getAmplifier() + 1);
|
||||
// }
|
||||
|
||||
if (potioneffect.getDuration() > 20)
|
||||
{
|
||||
s1 = s1 + " (" + Potion.getDurationString(potioneffect) + ")";
|
||||
}
|
||||
|
||||
if (potion.isBadEffect())
|
||||
{
|
||||
tooltip.add(TextColor.RED + s1);
|
||||
}
|
||||
else
|
||||
{
|
||||
tooltip.add(TextColor.LGRAY + s1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String s = "Wirkungslos";
|
||||
tooltip.add(TextColor.LGRAY + s);
|
||||
}
|
||||
|
||||
if (!multimap.isEmpty())
|
||||
{
|
||||
tooltip.add("");
|
||||
tooltip.add(TextColor.DMAGENTA + "Auswirkungen:");
|
||||
|
||||
for (Entry<Attribute, Set<AttributeModifier>> entry1 : multimap.entrySet())
|
||||
{
|
||||
for(AttributeModifier attributemodifier2 : entry1.getValue()) {
|
||||
double d0 = attributemodifier2.getAmount();
|
||||
double d1;
|
||||
|
||||
if (!attributemodifier2.isMultiplied())
|
||||
{
|
||||
d1 = attributemodifier2.getAmount();
|
||||
}
|
||||
else
|
||||
{
|
||||
d1 = attributemodifier2.getAmount() * 100.0D;
|
||||
}
|
||||
|
||||
if (d0 > 0.0D)
|
||||
{
|
||||
tooltip.add(TextColor.BLUE + String.format("+%s" + (attributemodifier2.isMultiplied() ? "%%" : "") + " %s", ItemStack.DECIMALFORMAT.format(d1), entry1.getKey().getDisplayName()));
|
||||
}
|
||||
else if (d0 < 0.0D)
|
||||
{
|
||||
d1 = d1 * -1.0D;
|
||||
tooltip.add(TextColor.RED + String.format("-%s" + (attributemodifier2.isMultiplied() ? "%%" : "") + " %s", ItemStack.DECIMALFORMAT.format(d1), entry1.getKey().getDisplayName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasEffect(ItemStack stack)
|
||||
{
|
||||
List<PotionEffect> list = this.getEffects(stack);
|
||||
return list != null && !list.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
*/
|
||||
public void getSubItems(Item itemIn, CheatTab tab, List<ItemStack> subItems)
|
||||
{
|
||||
super.getSubItems(itemIn, tab, subItems);
|
||||
subItems.add(new ItemStack(itemIn, 1, 16384));
|
||||
|
||||
if (SUB_ITEMS_CACHE.isEmpty())
|
||||
{
|
||||
for (int i = 0; i <= 15; ++i)
|
||||
{
|
||||
for (int j = 0; j <= 1; ++j)
|
||||
{
|
||||
int lvt_6_1_;
|
||||
|
||||
if (j == 0)
|
||||
{
|
||||
lvt_6_1_ = i | 8192;
|
||||
}
|
||||
else
|
||||
{
|
||||
lvt_6_1_ = i | 16384;
|
||||
}
|
||||
|
||||
for (int l = 0; l <= 2; ++l)
|
||||
{
|
||||
int i1 = lvt_6_1_;
|
||||
|
||||
if (l != 0)
|
||||
{
|
||||
if (l == 1)
|
||||
{
|
||||
i1 = lvt_6_1_ | 32;
|
||||
}
|
||||
else if (l == 2)
|
||||
{
|
||||
i1 = lvt_6_1_ | 64;
|
||||
}
|
||||
}
|
||||
|
||||
List<PotionEffect> list = PotionHelper.getPotionEffects(i1, false);
|
||||
|
||||
if (list != null && !list.isEmpty())
|
||||
{
|
||||
SUB_ITEMS_CACHE.put(list, Integer.valueOf(i1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Iterator iterator = SUB_ITEMS_CACHE.values().iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
int j1 = ((Integer)iterator.next()).intValue();
|
||||
subItems.add(new ItemStack(itemIn, 1, j1));
|
||||
}
|
||||
}
|
||||
|
||||
// public Set<String> getValidTags() {
|
||||
// return Sets.newHashSet("CustomPotionEffects");
|
||||
// }
|
||||
|
||||
// public boolean validateNbt(NBTTagCompound tag, boolean adv) {
|
||||
// if(tag.hasKey("CustomPotionEffects")) {
|
||||
// if(!adv) {
|
||||
// return false;
|
||||
// }
|
||||
// if(!tag.hasKey("CustomPotionEffects", 9)) {
|
||||
// return false;
|
||||
// }
|
||||
// NBTTagList effects = tag.getTagList("CustomPotionEffects", 10);
|
||||
// if(effects.hasNoTags()) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public ItemMeshDefinition getMesher() {
|
||||
return new ItemMeshDefinition()
|
||||
{
|
||||
public String getModelLocation(ItemStack stack)
|
||||
{
|
||||
return ItemPotion.isSplash(stack.getMetadata()) ? ("item/potion#16384" + '#' + "inventory") : ("item/potion#0" + '#' + "inventory");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void getRenderItems(Item itemIn, List<ItemStack> subItems) {
|
||||
subItems.add(new ItemStack(itemIn, 1, 0));
|
||||
subItems.add(new ItemStack(itemIn, 1, 16384));
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(this.getTransform(), "potion_overlay",
|
||||
isSplash(meta) ? "potion_bottle_splash" : "potion_bottle_drinkable");
|
||||
}
|
||||
}
|
22
java/src/game/item/ItemPressurePlate.java
Executable file
22
java/src/game/item/ItemPressurePlate.java
Executable file
|
@ -0,0 +1,22 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.block.BlockBasePressurePlate;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
|
||||
public class ItemPressurePlate extends ItemBlock {
|
||||
public ItemPressurePlate(Block block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(new ModelBlock(((BlockBasePressurePlate)this.block).getTexture())
|
||||
.add(1, 6, 1, 15, 10, 15)
|
||||
.d().uv(1, 1, 15, 15).noCull()
|
||||
.u().uv(1, 1, 15, 15).noCull()
|
||||
.n().uv(1, 6, 15, 10).noCull()
|
||||
.s().uv(1, 6, 15, 10).noCull()
|
||||
.w().uv(1, 6, 15, 10).noCull()
|
||||
.e().uv(1, 6, 15, 10).noCull(), this.getTransform());
|
||||
}
|
||||
}
|
13
java/src/game/item/ItemRecord.java
Executable file
13
java/src/game/item/ItemRecord.java
Executable file
|
@ -0,0 +1,13 @@
|
|||
package game.item;
|
||||
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
|
||||
public class ItemRecord extends Item {
|
||||
public ItemRecord() {
|
||||
this.setTab(CheatTab.tabMisc);
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(this.getTransform(), "record_old");
|
||||
}
|
||||
}
|
59
java/src/game/item/ItemRedstone.java
Executable file
59
java/src/game/item/ItemRedstone.java
Executable file
|
@ -0,0 +1,59 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.entity.Entity;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemRedstone extends Item
|
||||
{
|
||||
public ItemRedstone()
|
||||
{
|
||||
this.setTab(CheatTab.tabTech);
|
||||
}
|
||||
|
||||
public Block getBlock()
|
||||
{
|
||||
return Blocks.redstone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
boolean flag = worldIn.getState(pos).getBlock().isReplaceable(worldIn, pos);
|
||||
BlockPos blockpos = flag ? pos : pos.offset(side);
|
||||
|
||||
if (!playerIn.canPlayerEdit(blockpos, side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Block block = worldIn.getState(blockpos).getBlock();
|
||||
|
||||
if (!worldIn.canBlockBePlaced(block, blockpos, false, side, (Entity)null, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (Blocks.redstone.canPlaceBlockAt(worldIn, blockpos))
|
||||
{
|
||||
--stack.stackSize;
|
||||
worldIn.setState(blockpos, Blocks.redstone.getState());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return true;
|
||||
}
|
||||
}
|
81
java/src/game/item/ItemReed.java
Executable file
81
java/src/game/item/ItemReed.java
Executable file
|
@ -0,0 +1,81 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.block.BlockSnow;
|
||||
import game.entity.Entity;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.State;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemReed extends Item
|
||||
{
|
||||
private Block block;
|
||||
|
||||
public ItemReed(Block block)
|
||||
{
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public Block getBlock()
|
||||
{
|
||||
return this.block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (block == Blocks.snow_layer && ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue() < 1)
|
||||
{
|
||||
side = Facing.UP;
|
||||
}
|
||||
else if (!block.isReplaceable(worldIn, pos))
|
||||
{
|
||||
pos = pos.offset(side);
|
||||
}
|
||||
|
||||
if (!playerIn.canPlayerEdit(pos, side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (stack.stackSize == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (worldIn.canBlockBePlaced(this.block, pos, false, side, (Entity)null, stack))
|
||||
{
|
||||
State iblockstate1 = this.block.onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, 0, playerIn);
|
||||
|
||||
if (worldIn.setState(pos, iblockstate1, 3))
|
||||
{
|
||||
iblockstate1 = worldIn.getState(pos);
|
||||
|
||||
if (iblockstate1.getBlock() == this.block)
|
||||
{
|
||||
ItemBlock.setTileEntityNBT(worldIn, playerIn, pos, stack);
|
||||
iblockstate1.getBlock().onBlockPlacedBy(worldIn, pos, iblockstate1, playerIn, stack);
|
||||
}
|
||||
|
||||
worldIn.playSound(this.block.sound.getPlaceSound(), (double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), (this.block.sound.getVolume() + 1.0F) / 2.0F, this.block.sound.getFrequency() * 0.8F);
|
||||
--stack.stackSize;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return this.block.isMagnetic();
|
||||
}
|
||||
}
|
9
java/src/game/item/ItemRod.java
Executable file
9
java/src/game/item/ItemRod.java
Executable file
|
@ -0,0 +1,9 @@
|
|||
package game.item;
|
||||
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
|
||||
public class ItemRod extends Item {
|
||||
public Transforms getTransform() {
|
||||
return Transforms.ROD;
|
||||
}
|
||||
}
|
48
java/src/game/item/ItemSaddle.java
Executable file
48
java/src/game/item/ItemSaddle.java
Executable file
|
@ -0,0 +1,48 @@
|
|||
package game.item;
|
||||
|
||||
import game.entity.animal.EntityPig;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.types.EntityLiving;
|
||||
|
||||
public class ItemSaddle extends Item
|
||||
{
|
||||
public ItemSaddle()
|
||||
{
|
||||
this.maxStackSize = 1;
|
||||
this.setTab(CheatTab.tabTools);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the item can be used on the given entity, e.g. shears on sheep.
|
||||
*/
|
||||
public boolean itemInteractionForEntity(ItemStack stack, EntityNPC playerIn, EntityLiving target)
|
||||
{
|
||||
if (target instanceof EntityPig)
|
||||
{
|
||||
EntityPig entitypig = (EntityPig)target;
|
||||
|
||||
if (!entitypig.getSaddled() && !entitypig.isChild())
|
||||
{
|
||||
entitypig.setSaddled(true);
|
||||
// entitypig.worldObj.playSoundAtEntity(entitypig, "mob.horse.leather", 0.5F, 1.0F);
|
||||
--stack.stackSize;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
|
||||
* the damage on the stack.
|
||||
*/
|
||||
public boolean hitEntity(ItemStack stack, EntityLiving target, EntityLiving attacker)
|
||||
{
|
||||
this.itemInteractionForEntity(stack, (EntityNPC)null, target);
|
||||
return true;
|
||||
}
|
||||
}
|
53
java/src/game/item/ItemSeedFood.java
Executable file
53
java/src/game/item/ItemSeedFood.java
Executable file
|
@ -0,0 +1,53 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemSeedFood extends ItemFood
|
||||
{
|
||||
private Block crops;
|
||||
|
||||
/** Block ID of the soil this seed food should be planted on. */
|
||||
private Block soilId;
|
||||
|
||||
public ItemSeedFood(int healAmount, Block crops, Block soil)
|
||||
{
|
||||
super(healAmount, false);
|
||||
this.crops = crops;
|
||||
this.soilId = soil;
|
||||
this.setTab(CheatTab.tabPlants);
|
||||
}
|
||||
|
||||
public Block getBlock()
|
||||
{
|
||||
return this.crops;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (side != Facing.UP)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!playerIn.canPlayerEdit(pos.offset(side), side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (worldIn.getState(pos).getBlock() == this.soilId && worldIn.isAirBlock(pos.up()))
|
||||
{
|
||||
worldIn.setState(pos.up(), this.crops.getState());
|
||||
--stack.stackSize;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
57
java/src/game/item/ItemSeeds.java
Executable file
57
java/src/game/item/ItemSeeds.java
Executable file
|
@ -0,0 +1,57 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemSeeds extends Item
|
||||
{
|
||||
private Block crops;
|
||||
|
||||
/** BlockID of the block the seeds can be planted on. */
|
||||
private Block soilBlockID;
|
||||
|
||||
public ItemSeeds(Block crops, Block soil)
|
||||
{
|
||||
this.crops = crops;
|
||||
this.soilBlockID = soil;
|
||||
this.setTab(CheatTab.tabPlants);
|
||||
}
|
||||
|
||||
public Block getBlock()
|
||||
{
|
||||
return this.crops;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (side != Facing.UP)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!playerIn.canPlayerEdit(pos.offset(side), side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (worldIn.getState(pos).getBlock() == this.soilBlockID && worldIn.isAirBlock(pos.up()))
|
||||
{
|
||||
worldIn.setState(pos.up(), this.crops.getState());
|
||||
--stack.stackSize;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.OFFSET1;
|
||||
}
|
||||
}
|
55
java/src/game/item/ItemShears.java
Executable file
55
java/src/game/item/ItemShears.java
Executable file
|
@ -0,0 +1,55 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.init.Blocks;
|
||||
import game.init.ToolMaterial;
|
||||
import game.material.Material;
|
||||
import game.world.BlockPos;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemShears extends Item
|
||||
{
|
||||
private final ToolMaterial material;
|
||||
|
||||
public ItemShears(ToolMaterial material)
|
||||
{
|
||||
this.setMaxStackSize(1);
|
||||
this.setMaxDamage(material.getMaxUses() - 12);
|
||||
this.setTab(CheatTab.tabTools);
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLiving playerIn)
|
||||
{
|
||||
if (blockIn.getShearsEfficiency() < 0) // blockIn.getMaterial() != Material.leaves && blockIn != Blocks.web && blockIn != Blocks.tallgrass && blockIn != Blocks.vine && blockIn != Blocks.tripwire && blockIn != Blocks.wool)
|
||||
{
|
||||
return super.onBlockDestroyed(stack, worldIn, blockIn, pos, playerIn);
|
||||
}
|
||||
else
|
||||
{
|
||||
stack.damageItem(1, playerIn);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canHarvestBlock(Block blockIn)
|
||||
{
|
||||
return blockIn.getMaterial() == Material.web || blockIn == Blocks.redstone || blockIn == Blocks.string;
|
||||
}
|
||||
|
||||
public float getStrVsBlock(ItemStack stack, Block state)
|
||||
{
|
||||
return state.getShearsEfficiency() <= 0 ? 1.0F : (((float)state.getShearsEfficiency()) * (this.material.getEfficiencyOnProperMaterial() - 1.0F));
|
||||
// state != Blocks.web && state.getMaterial() != Material.leaves ? (state == Blocks.wool ? 5.0F : super.getStrVsBlock(stack, state)) : 15.0F;
|
||||
}
|
||||
|
||||
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
|
||||
{
|
||||
return this.material.isRepairItem(repair.getItem()) ? true : super.getIsRepairable(toRepair, repair);
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return this.material.isMagnetic();
|
||||
}
|
||||
}
|
93
java/src/game/item/ItemSign.java
Executable file
93
java/src/game/item/ItemSign.java
Executable file
|
@ -0,0 +1,93 @@
|
|||
package game.item;
|
||||
|
||||
import game.ExtMath;
|
||||
import game.block.Block;
|
||||
import game.block.BlockStandingSign;
|
||||
import game.block.BlockWallSign;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.tileentity.TileEntity;
|
||||
import game.tileentity.TileEntitySign;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemSign extends Item
|
||||
{
|
||||
public ItemSign()
|
||||
{
|
||||
this.setTab(CheatTab.tabDeco);
|
||||
}
|
||||
|
||||
public Block getBlock()
|
||||
{
|
||||
return Blocks.sign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (side == Facing.DOWN)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!worldIn.getState(pos).getBlock().getMaterial().isSolid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = pos.offset(side);
|
||||
|
||||
if (!playerIn.canPlayerEdit(pos, side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!Blocks.sign.canPlaceBlockAt(worldIn, pos))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (worldIn.client)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (side == Facing.UP)
|
||||
{
|
||||
int i = ExtMath.floord((double)((playerIn.rotYaw + 180.0F) * 16.0F / 360.0F) + 0.5D) & 15;
|
||||
worldIn.setState(pos, Blocks.sign.getState().withProperty(BlockStandingSign.ROTATION, Integer.valueOf(i)), 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
worldIn.setState(pos, Blocks.wall_sign.getState().withProperty(BlockWallSign.FACING, side), 3);
|
||||
}
|
||||
|
||||
--stack.stackSize;
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentity instanceof TileEntitySign && !ItemBlock.setTileEntityNBT(worldIn, playerIn, pos, stack))
|
||||
{
|
||||
playerIn.openEditSign((TileEntitySign)tileentity);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// public Set<String> getValidTags() {
|
||||
// return Sets.newHashSet("BlockEntityTag");
|
||||
// }
|
||||
//
|
||||
// protected boolean validateNbt(NBTTagCompound tag) {
|
||||
// if(tag.hasKey("BlockEntityTag")) {
|
||||
// if(!tag.hasKey("BlockEntityTag", 10)) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
}
|
188
java/src/game/item/ItemSkull.java
Executable file
188
java/src/game/item/ItemSkull.java
Executable file
|
@ -0,0 +1,188 @@
|
|||
package game.item;
|
||||
|
||||
import game.ExtMath;
|
||||
import game.block.Block;
|
||||
import game.block.BlockSkull;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Blocks;
|
||||
import game.model.ModelBakery;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.tileentity.TileEntity;
|
||||
import game.tileentity.TileEntitySkull;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.State;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemSkull extends Item
|
||||
{
|
||||
public ItemSkull()
|
||||
{
|
||||
this.setTab(CheatTab.tabDeco);
|
||||
// this.setMaxDamage(0);
|
||||
// this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
public Block getBlock()
|
||||
{
|
||||
return Blocks.skull;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (side == Facing.DOWN)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
boolean flag = block.isReplaceable(worldIn, pos);
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
if (!worldIn.getState(pos).getBlock().getMaterial().isSolid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
pos = pos.offset(side);
|
||||
}
|
||||
|
||||
if (!playerIn.canPlayerEdit(pos, side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!Blocks.skull.canPlaceBlockAt(worldIn, pos))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!worldIn.client)
|
||||
{
|
||||
worldIn.setState(pos, Blocks.skull.getState().withProperty(BlockSkull.FACING, side), 3);
|
||||
int i = 0;
|
||||
|
||||
if (side == Facing.UP)
|
||||
{
|
||||
i = ExtMath.floord((double)(playerIn.rotYaw * 16.0F / 360.0F) + 0.5D) & 15;
|
||||
}
|
||||
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
|
||||
if (tileentity instanceof TileEntitySkull)
|
||||
{
|
||||
TileEntitySkull tileentityskull = (TileEntitySkull)tileentity;
|
||||
|
||||
// if (stack.getMetadata() == 3)
|
||||
// {
|
||||
// String user = null;
|
||||
//
|
||||
// if (stack.hasTagCompound())
|
||||
// {
|
||||
// NBTTagCompound nbttagcompound = stack.getTagCompound();
|
||||
//
|
||||
// if (nbttagcompound.hasKey("SkullOwner", 8) && nbttagcompound.getString("SkullOwner").length() > 0)
|
||||
// {
|
||||
// user = nbttagcompound.getString("SkullOwner");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// tileentityskull.setUser(user);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// tileentityskull.setType(stack.getMetadata());
|
||||
// }
|
||||
|
||||
tileentityskull.setSkullRotation(i);
|
||||
// Blocks.skull.checkWitherSpawn(worldIn, pos, tileentityskull);
|
||||
}
|
||||
|
||||
--stack.stackSize;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
|
||||
// */
|
||||
// public void getSubItems(Item itemIn, CreativeTabs tab, List<ItemStack> subItems)
|
||||
// {
|
||||
// for (int i = 0; i < skullTypes.length; ++i)
|
||||
// {
|
||||
// subItems.add(new ItemStack(itemIn, 1, i));
|
||||
// }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
// * placed as a Block (mostly used with ItemBlocks).
|
||||
// */
|
||||
// public int getMetadata(int damage)
|
||||
// {
|
||||
// return damage;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
// * different names based on their damage or NBT.
|
||||
// */
|
||||
// public String getUnlocalizedName(ItemStack stack)
|
||||
// {
|
||||
// int i = stack.getMetadata();
|
||||
//
|
||||
// if (i < 0 || i >= skullTypes.length)
|
||||
// {
|
||||
// i = 0;
|
||||
// }
|
||||
//
|
||||
// return super.getUnlocalizedName() + "." + skullTypes[i];
|
||||
// }
|
||||
|
||||
// public String getDisplay(ItemStack stack)
|
||||
// {
|
||||
// if (stack.hasTagCompound())
|
||||
// {
|
||||
// if (stack.getTagCompound().hasKey("SkullOwner", 8))
|
||||
// {
|
||||
// return super.getDisplay(stack) + " von " + stack.getTagCompound().getString("SkullOwner");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return super.getDisplay(stack);
|
||||
// }
|
||||
|
||||
// public Set<String> getValidTags() {
|
||||
// return Sets.newHashSet("SkullOwner");
|
||||
// }
|
||||
//
|
||||
// protected boolean validateNbt(NBTTagCompound tag) {
|
||||
// if(tag.hasKey("SkullOwner")) {
|
||||
//// if(!adv) {
|
||||
//// return false;
|
||||
//// }
|
||||
// if(!tag.hasKey("SkullOwner", 8)) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.SKULL;
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(ModelBakery.MODEL_ENTITY, this.getTransform());
|
||||
}
|
||||
}
|
185
java/src/game/item/ItemSlab.java
Executable file
185
java/src/game/item/ItemSlab.java
Executable file
|
@ -0,0 +1,185 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.block.BlockSlab;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.State;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemSlab extends ItemBlock
|
||||
{
|
||||
private final BlockSlab slab;
|
||||
|
||||
public ItemSlab(BlockSlab slab)
|
||||
{
|
||||
super(slab);
|
||||
this.slab = slab;
|
||||
// this.setMaxDamage(0);
|
||||
// this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
// * placed as a Block (mostly used with ItemBlocks).
|
||||
// */
|
||||
// public int getMetadata(int damage)
|
||||
// {
|
||||
// return damage;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have
|
||||
// * different names based on their damage or NBT.
|
||||
// */
|
||||
// public String getUnlocalizedName(ItemStack stack)
|
||||
// {
|
||||
// return this.slab.getUnlocalizedName(stack.getMetadata());
|
||||
// }
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (stack.stackSize == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!playerIn.canPlayerEdit(pos.offset(side), side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Object object = this.slab.getVariant(stack);
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
|
||||
if (iblockstate.getBlock() == this.slab)
|
||||
{
|
||||
// IProperty iproperty = this.slab.getVariantProperty();
|
||||
// Comparable comparable = iblockstate.getValue(iproperty);
|
||||
Facing blockslab$enumblockhalf = iblockstate.getValue(BlockSlab.FACING);
|
||||
|
||||
if ((side == Facing.UP && blockslab$enumblockhalf == Facing.DOWN || side == Facing.DOWN && blockslab$enumblockhalf == Facing.UP) && !iblockstate.getValue(BlockSlab.DOUBLE))
|
||||
{
|
||||
State iblockstate1 = this.slab.getState().withProperty(BlockSlab.DOUBLE, true);
|
||||
|
||||
if (worldIn.checkNoEntityCollision(this.slab.getCollisionBoundingBox(worldIn, pos, iblockstate1)) && worldIn.setState(pos, iblockstate1, 3))
|
||||
{
|
||||
worldIn.playSound(this.slab.sound.getPlaceSound(), (double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), (this.slab.sound.getVolume() + 1.0F) / 2.0F, this.slab.sound.getFrequency() * 0.8F);
|
||||
--stack.stackSize;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return this.tryPlace(stack, worldIn, pos.offset(side)) ? true : (this.tryVerticalPlace(stack, playerIn, worldIn, pos, side, hitX, hitY, hitZ) ? true : super.onItemUse(stack, playerIn, worldIn, pos, side, hitX, hitY, hitZ));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, Facing side, EntityNPC player, ItemStack stack)
|
||||
{
|
||||
BlockPos blockpos = pos;
|
||||
// IProperty iproperty = this.slab.getVariantProperty();
|
||||
// Object object = this.slab.getVariant(stack);
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
|
||||
if (iblockstate.getBlock() == this.slab && !iblockstate.getValue(BlockSlab.DOUBLE))
|
||||
{
|
||||
boolean up = iblockstate.getValue(BlockSlab.FACING) == Facing.UP;
|
||||
|
||||
if ((side == Facing.UP && !up || side == Facing.DOWN && up)) // && object == iblockstate.getValue(iproperty))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
pos = pos.offset(side);
|
||||
State iblockstate1 = worldIn.getState(pos);
|
||||
return iblockstate1.getBlock() == this.slab && !iblockstate1.getValue(BlockSlab.DOUBLE) ? true : super.canPlaceBlockOnSide(worldIn, blockpos, side, player, stack);
|
||||
}
|
||||
|
||||
// private boolean tryPlaceNormal(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
// if (worldIn.canBlockBePlaced(this.block, pos, false, side, (Entity)null, stack))
|
||||
// {
|
||||
// int i = this.getMetadata(stack.getMetadata());
|
||||
// IBlockState iblockstate1 = this.block.onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, i, playerIn);
|
||||
//
|
||||
// if (worldIn.setBlockState(pos, iblockstate1, 3))
|
||||
// {
|
||||
// iblockstate1 = worldIn.getBlockState(pos);
|
||||
//
|
||||
// if (iblockstate1.getBlock() == this.block)
|
||||
// {
|
||||
// setTileEntityNBT(worldIn, playerIn, pos, stack);
|
||||
// this.block.onBlockPlacedBy(worldIn, pos, iblockstate1, playerIn, stack);
|
||||
// }
|
||||
//
|
||||
// worldIn.playSound(this.block.stepSound.getPlaceSound(), (double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), (this.block.stepSound.getVolume() + 1.0F) / 2.0F, this.block.stepSound.getFrequency() * 0.8F);
|
||||
// --stack.stackSize;
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
|
||||
private boolean tryPlace(ItemStack stack, World worldIn, BlockPos pos)
|
||||
{
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
|
||||
if (iblockstate.getBlock() == this.slab)
|
||||
{
|
||||
// Comparable comparable = iblockstate.getValue(this.slab.getVariantProperty());
|
||||
|
||||
if (!iblockstate.getValue(BlockSlab.DOUBLE))
|
||||
{
|
||||
State iblockstate1 = this.slab.getState().withProperty(BlockSlab.DOUBLE, true);
|
||||
|
||||
if (worldIn.checkNoEntityCollision(this.slab.getCollisionBoundingBox(worldIn, pos, iblockstate1)) && worldIn.setState(pos, iblockstate1, 3))
|
||||
{
|
||||
worldIn.playSound(this.slab.sound.getPlaceSound(), (double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), (this.slab.sound.getVolume() + 1.0F) / 2.0F, this.slab.sound.getFrequency() * 0.8F);
|
||||
--stack.stackSize;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean tryVerticalPlace(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ) {
|
||||
if(hitY >= 0.34f && hitY <= 0.66f) {
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (!block.isReplaceable(worldIn, pos))
|
||||
{
|
||||
pos = pos.offset(side);
|
||||
}
|
||||
|
||||
// BlockVerticalSlab vslab = (stack.getMetadata() & 7) < 4 ? this.verticalSlab1 : this.verticalSlab2;
|
||||
|
||||
if (worldIn.canBlockBePlaced(this.slab, pos, false, side, null, stack))
|
||||
{
|
||||
// int i = this.getMetadata(stack.getMetadata());
|
||||
State iblockstate1 = this.slab.getState().withProperty(BlockSlab.FACING, playerIn.getHorizontalFacing()); // .onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, i, playerIn);
|
||||
|
||||
if (worldIn.setState(pos, iblockstate1, 3))
|
||||
{
|
||||
worldIn.playSound(this.slab.sound.getPlaceSound(), (double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), (this.slab.sound.getVolume() + 1.0F) / 2.0F, this.slab.sound.getFrequency() * 0.8F);
|
||||
--stack.stackSize;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
9
java/src/game/item/ItemSmall.java
Executable file
9
java/src/game/item/ItemSmall.java
Executable file
|
@ -0,0 +1,9 @@
|
|||
package game.item;
|
||||
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
|
||||
public class ItemSmall extends Item {
|
||||
public Transforms getTransform() {
|
||||
return Transforms.OFFSET1;
|
||||
}
|
||||
}
|
77
java/src/game/item/ItemSnow.java
Executable file
77
java/src/game/item/ItemSnow.java
Executable file
|
@ -0,0 +1,77 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.block.BlockSnow;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.world.BlockPos;
|
||||
import game.world.BoundingBox;
|
||||
import game.world.Facing;
|
||||
import game.world.State;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemSnow extends ItemBlock
|
||||
{
|
||||
public ItemSnow(Block block)
|
||||
{
|
||||
super(block);
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is right-clicked with this Item
|
||||
*/
|
||||
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, BlockPos pos, Facing side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (stack.stackSize == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!playerIn.canPlayerEdit(pos, side, stack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
State iblockstate = worldIn.getState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
BlockPos blockpos = pos;
|
||||
|
||||
if ((side != Facing.UP || block != this.block) && !block.isReplaceable(worldIn, pos))
|
||||
{
|
||||
blockpos = pos.offset(side);
|
||||
iblockstate = worldIn.getState(blockpos);
|
||||
block = iblockstate.getBlock();
|
||||
}
|
||||
|
||||
if (block == this.block)
|
||||
{
|
||||
int i = ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue();
|
||||
|
||||
if (i <= 7)
|
||||
{
|
||||
State iblockstate1 = iblockstate.withProperty(BlockSnow.LAYERS, Integer.valueOf(i + 1));
|
||||
BoundingBox axisalignedbb = this.block.getCollisionBoundingBox(worldIn, blockpos, iblockstate1);
|
||||
|
||||
if (axisalignedbb != null && worldIn.checkNoEntityCollision(axisalignedbb) && worldIn.setState(blockpos, iblockstate1, 2))
|
||||
{
|
||||
worldIn.playSound(this.block.sound.getPlaceSound(), (double)((float)blockpos.getX() + 0.5F), (double)((float)blockpos.getY() + 0.5F), (double)((float)blockpos.getZ() + 0.5F), (this.block.sound.getVolume() + 1.0F) / 2.0F, this.block.sound.getFrequency() * 0.8F);
|
||||
--stack.stackSize;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.onItemUse(stack, playerIn, worldIn, blockpos, side, hitX, hitY, hitZ);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given ItemStack damage value into a metadata value to be placed in the world when this Item is
|
||||
* placed as a Block (mostly used with ItemBlocks).
|
||||
*/
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
}
|
35
java/src/game/item/ItemSnowball.java
Executable file
35
java/src/game/item/ItemSnowball.java
Executable file
|
@ -0,0 +1,35 @@
|
|||
package game.item;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.projectile.EntitySnowball;
|
||||
import game.init.SoundEvent;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemSnowball extends Item
|
||||
{
|
||||
public ItemSnowball()
|
||||
{
|
||||
this.setTab(CheatTab.tabTools);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
// if (!playerIn.creative)
|
||||
// {
|
||||
--itemStackIn.stackSize;
|
||||
// }
|
||||
|
||||
worldIn.playSoundAtEntity(playerIn, SoundEvent.THROW, 0.5F, 0.4F / (itemRand.floatv() * 0.4F + 0.8F));
|
||||
|
||||
if (!worldIn.client)
|
||||
{
|
||||
worldIn.spawnEntityInWorld(new EntitySnowball(worldIn, playerIn));
|
||||
}
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return itemStackIn;
|
||||
}
|
||||
}
|
29
java/src/game/item/ItemSoup.java
Executable file
29
java/src/game/item/ItemSoup.java
Executable file
|
@ -0,0 +1,29 @@
|
|||
package game.item;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.Items;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemSoup extends ItemFood
|
||||
{
|
||||
public ItemSoup(int healAmount)
|
||||
{
|
||||
super(healAmount, false);
|
||||
this.setMaxStackSize(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
|
||||
* the Item before the action is complete.
|
||||
*/
|
||||
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
super.onItemUseFinish(stack, worldIn, playerIn);
|
||||
return new ItemStack(Items.bowl);
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.OFFSET1;
|
||||
}
|
||||
}
|
49
java/src/game/item/ItemSpaceNavigator.java
Executable file
49
java/src/game/item/ItemSpaceNavigator.java
Executable file
|
@ -0,0 +1,49 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.UniverseRegistry;
|
||||
import game.world.BlockPos;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemSpaceNavigator extends ItemMagnetic {
|
||||
public static String formatImperialTime(World world, boolean days) {
|
||||
long time = world.getDayTime();
|
||||
long year = time / UniverseRegistry.EARTH_YEAR;
|
||||
long frac = (time * 1000L / UniverseRegistry.EARTH_YEAR) % 1000L;
|
||||
if(!world.dimension.getType().time) {
|
||||
return String.format("%d.%03d.%03d.M%d" + (days ? " T???.??? D???.???.G?" : ""), world.dimension.getTimeQualifier(),
|
||||
frac, year % 1000L, year / 1000L);
|
||||
}
|
||||
long day = time / world.dimension.getRotationalPeriod();
|
||||
time = time % world.dimension.getRotationalPeriod();
|
||||
return String.format("%d.%03d.%03d.M%d" + (days ? " T%03d.%03d D%03d.%03d.G%d" : ""), world.dimension.getTimeQualifier(),
|
||||
frac, year % 1000L, year / 1000L,
|
||||
time / 1000L, time % 1000L, (day / 1000L) % 1000L, day % 1000L, day / 1000000L);
|
||||
}
|
||||
|
||||
public ItemSpaceNavigator() {
|
||||
this.setMaxStackSize(1);
|
||||
this.setColor(TextColor.DGREEN);
|
||||
}
|
||||
|
||||
public String getHotbarText(EntityNPC player, ItemStack stack) {
|
||||
BlockPos pos = player.getPosition();
|
||||
return TextColor.ORANGE + formatImperialTime(player.worldObj, false) + " / " +
|
||||
String.format("%s (%d) bei %d, %d, %d", player.worldObj.dimension.getFormattedName(false) + TextColor.ORANGE,
|
||||
player.worldObj.dimension.getDimensionId(), pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public void addInformation(ItemStack stack, EntityNPC player, List<String> tooltip) {
|
||||
tooltip.add(TextColor.ORANGE + formatImperialTime(player.worldObj, true));
|
||||
String[] dims = TextColor.stripCodes(player.worldObj.dimension.getFormattedName(true)).split(" / ");
|
||||
for(int z = dims.length - 1; z > 0; z--) {
|
||||
tooltip.add(TextColor.ORANGE + dims[z]);
|
||||
}
|
||||
BlockPos pos = player.getPosition();
|
||||
tooltip.add(TextColor.ORANGE + String.format("%s (%d) bei %d, %d, %d", player.worldObj.dimension.getFormattedName(false)
|
||||
+ TextColor.ORANGE, player.worldObj.dimension.getDimensionId(), pos.getX(), pos.getY(), pos.getZ()));
|
||||
}
|
||||
}
|
28
java/src/game/item/ItemSpade.java
Executable file
28
java/src/game/item/ItemSpade.java
Executable file
|
@ -0,0 +1,28 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.init.ToolMaterial;
|
||||
import game.material.Material;
|
||||
|
||||
public class ItemSpade extends ItemTool
|
||||
{
|
||||
// private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(new Block[] {
|
||||
// Blocks.clay, Blocks.dirt, Blocks.farmland, Blocks.grass, Blocks.gravel, Blocks.mycelium, Blocks.sand, Blocks.snow, Blocks.snow_layer, Blocks.soul_sand
|
||||
// });
|
||||
|
||||
public ItemSpade(ToolMaterial material)
|
||||
{
|
||||
super(1, material);
|
||||
}
|
||||
|
||||
public boolean canUseOn(ItemStack stack, Block state)
|
||||
{
|
||||
return state.canShovelHarvest();
|
||||
}
|
||||
|
||||
public boolean canHarvestBlock(Block blockIn)
|
||||
{
|
||||
// return blockIn == Blocks.snow_layer ? true : blockIn == Blocks.snow;
|
||||
return blockIn.getMaterial() == Material.snow ? true : blockIn.getMaterial() == Material.craftedSnow;
|
||||
}
|
||||
}
|
1297
java/src/game/item/ItemStack.java
Executable file
1297
java/src/game/item/ItemStack.java
Executable file
File diff suppressed because it is too large
Load diff
9
java/src/game/item/ItemStick.java
Executable file
9
java/src/game/item/ItemStick.java
Executable file
|
@ -0,0 +1,9 @@
|
|||
package game.item;
|
||||
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
|
||||
public class ItemStick extends Item {
|
||||
public Transforms getTransform() {
|
||||
return Transforms.TOOL;
|
||||
}
|
||||
}
|
166
java/src/game/item/ItemSword.java
Executable file
166
java/src/game/item/ItemSword.java
Executable file
|
@ -0,0 +1,166 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import game.block.Block;
|
||||
import game.collect.Sets;
|
||||
import game.entity.attributes.Attribute;
|
||||
import game.entity.attributes.AttributeModifier;
|
||||
import game.entity.attributes.Attributes;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.init.Blocks;
|
||||
import game.init.ToolMaterial;
|
||||
import game.material.Material;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.world.BlockPos;
|
||||
import game.world.World;
|
||||
|
||||
public class ItemSword extends Item
|
||||
{
|
||||
private int attackDamage;
|
||||
private final ToolMaterial material;
|
||||
|
||||
public ItemSword(ToolMaterial material)
|
||||
{
|
||||
this.material = material;
|
||||
this.maxStackSize = 1;
|
||||
this.setMaxDamage(material.getMaxUses());
|
||||
this.setTab(CheatTab.tabCombat);
|
||||
this.attackDamage = 4 + material.getDamageVsEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of damage this item will deal. One heart of damage is equal to 2 damage points.
|
||||
*/
|
||||
public int getDamageVsEntity()
|
||||
{
|
||||
return this.material.getDamageVsEntity();
|
||||
}
|
||||
|
||||
public ToolMaterial getToolMaterial()
|
||||
{
|
||||
return this.material;
|
||||
}
|
||||
|
||||
public float getStrVsBlock(ItemStack stack, Block state)
|
||||
{
|
||||
if (state == Blocks.web)
|
||||
{
|
||||
return 15.0F;
|
||||
}
|
||||
else
|
||||
{
|
||||
Material material = state.getMaterial();
|
||||
return material != Material.plants && material != Material.vine && material != Material.coral && material != Material.leaves && material != Material.gourd ? 1.0F : 1.5F;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
|
||||
* the damage on the stack.
|
||||
*/
|
||||
public boolean hitEntity(ItemStack stack, EntityLiving target, EntityLiving attacker)
|
||||
{
|
||||
stack.damageItem(1, attacker);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
|
||||
*/
|
||||
public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLiving playerIn)
|
||||
{
|
||||
if ((double)blockIn.getBlockHardness(worldIn, pos) != 0.0D)
|
||||
{
|
||||
stack.damageItem(2, playerIn);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Returns True is the item is renderer in full 3D when hold.
|
||||
// */
|
||||
// public boolean isFull3D()
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
/**
|
||||
* returns the action that specifies what animation to play when the items is being used
|
||||
*/
|
||||
public ItemAction getItemUseAction(ItemStack stack)
|
||||
{
|
||||
return ItemAction.BLOCK;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long it takes to use or consume an item
|
||||
*/
|
||||
public int getMaxItemUseDuration(ItemStack stack)
|
||||
{
|
||||
return 72000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
||||
*/
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn));
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this Item can harvest the given Block
|
||||
*/
|
||||
public boolean canHarvestBlock(Block blockIn)
|
||||
{
|
||||
return blockIn == Blocks.web;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enchantability factor of the item, most of the time is based on material.
|
||||
*/
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return this.material.getEnchantability();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Return the name for this tool's material.
|
||||
// */
|
||||
// public String getToolMaterialName()
|
||||
// {
|
||||
// return this.material.toString();
|
||||
// }
|
||||
|
||||
/**
|
||||
* Return whether this item is repairable in an anvil.
|
||||
*/
|
||||
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
|
||||
{
|
||||
return this.material.isRepairItem(repair.getItem()) ? true : super.getIsRepairable(toRepair, repair);
|
||||
}
|
||||
|
||||
public Map<Attribute, Set<AttributeModifier>> getItemAttributeModifiers()
|
||||
{
|
||||
Map<Attribute, Set<AttributeModifier>> multimap = super.getItemAttributeModifiers();
|
||||
multimap.put(Attributes.ATTACK_DAMAGE, Sets.newHashSet(new AttributeModifier(Attributes.ITEM_VAL_ID, "Weapon modifier", this.attackDamage, false)));
|
||||
return multimap;
|
||||
}
|
||||
|
||||
// public boolean canBreakBlocks() {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return this.material.isMagnetic();
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.TOOL;
|
||||
}
|
||||
}
|
28
java/src/game/item/ItemTNT.java
Executable file
28
java/src/game/item/ItemTNT.java
Executable file
|
@ -0,0 +1,28 @@
|
|||
package game.item;
|
||||
|
||||
import game.block.Block;
|
||||
import game.color.TextColor;
|
||||
|
||||
public class ItemTNT extends ItemBlock
|
||||
{
|
||||
private static final String[] TIERS = new String[] {"II", "III", "IV", "V", "VI", "VII", "VIII"};
|
||||
|
||||
public ItemTNT(Block block)
|
||||
{
|
||||
super(block);
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
this.setColor(TextColor.RED);
|
||||
}
|
||||
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return (damage & 7) << 1;
|
||||
}
|
||||
|
||||
public String getDisplay(ItemStack stack)
|
||||
{
|
||||
int exp = stack.getMetadata() & 7;
|
||||
return super.getDisplay(stack) + (exp == 0 ? "" : " " + TIERS[exp-1]);
|
||||
}
|
||||
}
|
9
java/src/game/item/ItemTiny.java
Executable file
9
java/src/game/item/ItemTiny.java
Executable file
|
@ -0,0 +1,9 @@
|
|||
package game.item;
|
||||
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
|
||||
public class ItemTiny extends Item {
|
||||
public Transforms getTransform() {
|
||||
return Transforms.OFFSET2;
|
||||
}
|
||||
}
|
122
java/src/game/item/ItemTool.java
Executable file
122
java/src/game/item/ItemTool.java
Executable file
|
@ -0,0 +1,122 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import game.block.Block;
|
||||
import game.collect.Sets;
|
||||
import game.entity.attributes.Attribute;
|
||||
import game.entity.attributes.AttributeModifier;
|
||||
import game.entity.attributes.Attributes;
|
||||
import game.entity.types.EntityLiving;
|
||||
import game.init.ToolMaterial;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.world.BlockPos;
|
||||
import game.world.World;
|
||||
|
||||
public abstract class ItemTool extends Item
|
||||
{
|
||||
// private Set<Block> effectiveBlocks;
|
||||
protected float efficiencyOnProperMaterial = 4.0F;
|
||||
|
||||
/** Damage versus entities. */
|
||||
private int damageVsEntity;
|
||||
|
||||
/** The material this tool is made from. */
|
||||
protected ToolMaterial toolMaterial;
|
||||
|
||||
public ItemTool(int attackDamage, ToolMaterial material)
|
||||
{
|
||||
this.toolMaterial = material;
|
||||
// this.effectiveBlocks = effectiveBlocks;
|
||||
this.maxStackSize = 1;
|
||||
this.setMaxDamage(material.getMaxUses());
|
||||
this.efficiencyOnProperMaterial = material.getEfficiencyOnProperMaterial();
|
||||
this.damageVsEntity = attackDamage + material.getDamageVsEntity();
|
||||
this.setTab(CheatTab.tabTools);
|
||||
}
|
||||
|
||||
public abstract boolean canUseOn(ItemStack stack, Block state);
|
||||
|
||||
public float getStrVsBlock(ItemStack stack, Block state) {
|
||||
return !this.canUseOn(stack, state) ? 1.0F : this.efficiencyOnProperMaterial;
|
||||
}
|
||||
// {
|
||||
// return this.effectiveBlocks.contains(state) ? this.efficiencyOnProperMaterial : 1.0F;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
|
||||
* the damage on the stack.
|
||||
*/
|
||||
public boolean hitEntity(ItemStack stack, EntityLiving target, EntityLiving attacker)
|
||||
{
|
||||
stack.damageItem(2, attacker);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
|
||||
*/
|
||||
public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLiving playerIn)
|
||||
{
|
||||
if ((double)blockIn.getBlockHardness(worldIn, pos) != 0.0D)
|
||||
{
|
||||
stack.damageItem(1, playerIn);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Returns True is the item is renderer in full 3D when hold.
|
||||
// */
|
||||
// public boolean isFull3D()
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public ToolMaterial getToolMaterial()
|
||||
{
|
||||
return this.toolMaterial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the enchantability factor of the item, most of the time is based on material.
|
||||
*/
|
||||
public int getItemEnchantability()
|
||||
{
|
||||
return this.toolMaterial.getEnchantability();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Return the name for this tool's material.
|
||||
// */
|
||||
// public String getToolMaterialName()
|
||||
// {
|
||||
// return this.toolMaterial.toString();
|
||||
// }
|
||||
|
||||
/**
|
||||
* Return whether this item is repairable in an anvil.
|
||||
*/
|
||||
public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
|
||||
{
|
||||
return this.toolMaterial.isRepairItem(repair.getItem()) ? true : super.getIsRepairable(toRepair, repair);
|
||||
}
|
||||
|
||||
public Map<Attribute, Set<AttributeModifier>> getItemAttributeModifiers()
|
||||
{
|
||||
Map<Attribute, Set<AttributeModifier>> multimap = super.getItemAttributeModifiers();
|
||||
multimap.put(Attributes.ATTACK_DAMAGE, Sets.newHashSet(new AttributeModifier(Attributes.ITEM_VAL_ID, "Tool modifier", this.damageVsEntity, false)));
|
||||
return multimap;
|
||||
}
|
||||
|
||||
public boolean isMagnetic() {
|
||||
return this.toolMaterial.isMagnetic();
|
||||
}
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.TOOL;
|
||||
}
|
||||
}
|
32
java/src/game/item/ItemWall.java
Executable file
32
java/src/game/item/ItemWall.java
Executable file
|
@ -0,0 +1,32 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import game.block.Block;
|
||||
import game.block.BlockWall;
|
||||
import game.renderer.blockmodel.ModelBlock;
|
||||
|
||||
public class ItemWall extends ItemMultiTexture {
|
||||
public ItemWall(Block block, Block block2, Function<ItemStack, String> nameFunction) {
|
||||
super(block, block2, nameFunction);
|
||||
}
|
||||
|
||||
public ModelBlock getModel(String name, int meta) {
|
||||
return new ModelBlock(
|
||||
new ModelBlock(this.block.getStateFromMeta(this.getMetadata(meta)).getValue(BlockWall.VARIANT).getName()).noOcclude()
|
||||
.add(4, 0, 4, 12, 16, 12)
|
||||
.d().uv(4, 4, 12, 12)
|
||||
.u().uv(4, 4, 12, 12).noCull()
|
||||
.n().uv(4, 0, 12, 16).noCull()
|
||||
.s().uv(4, 0, 12, 16).noCull()
|
||||
.w().uv(4, 0, 12, 16).noCull()
|
||||
.e().uv(4, 0, 12, 16).noCull()
|
||||
.add(5, 0, 0, 11, 13, 16)
|
||||
.d().uv(5, 0, 11, 16)
|
||||
.u().uv(5, 0, 11, 16).noCull()
|
||||
.n().uv(5, 3, 11, 16)
|
||||
.s().uv(5, 3, 11, 16)
|
||||
.w().uv(0, 3, 16, 16).noCull()
|
||||
.e().uv(0, 3, 16, 16).noCull(), this.getTransform());
|
||||
}
|
||||
}
|
84
java/src/game/item/ItemWand.java
Executable file
84
java/src/game/item/ItemWand.java
Executable file
|
@ -0,0 +1,84 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import game.ExtMath;
|
||||
import game.color.TextColor;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.renderer.blockmodel.Transforms;
|
||||
import game.world.BlockPos;
|
||||
import game.world.Facing;
|
||||
import game.world.Vec3;
|
||||
import game.world.World;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public abstract class ItemWand extends Item {
|
||||
public ItemWand() {
|
||||
this.maxStackSize = 1;
|
||||
this.setTab(CheatTab.tabTools);
|
||||
}
|
||||
|
||||
// public boolean canBreakBlocks() {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// public final boolean canUseInAir() {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public boolean hasEffect(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// public boolean ignoresBlocks() {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// public boolean itemInteractionForEntity(ItemStack stack, EntityNPC playerIn, EntityLiving target)
|
||||
// {
|
||||
// if(playerIn.worldObj.client)
|
||||
// return true;
|
||||
// this.onUse(stack, (EntityNPCMP)playerIn, (WorldServer)playerIn.worldObj, new Vec3(target.posX, target.posY + target.height / 2.0, target.posZ));
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public final boolean onAction(ItemStack stack, EntityNPC player, World world, ItemControl control, BlockPos block) {
|
||||
if(control == ItemControl.SECONDARY && !world.client && block == null) {
|
||||
BlockPos vec = world.getBlockTrace(player, this.getRange(stack, player));
|
||||
if(vec != null)
|
||||
this.onUse(stack, player, (WorldServer)world, new Vec3(
|
||||
ExtMath.floord(vec.getX()) + 0.5, ExtMath.floord(vec.getY()) + 1.0, ExtMath.floord(vec.getZ()) + 0.5));
|
||||
}
|
||||
return control == ItemControl.SECONDARY;
|
||||
}
|
||||
|
||||
public final boolean onItemUse(ItemStack stack, EntityNPC player, World world, BlockPos pos, Facing side, float hitX, float hitY, float hitZ) {
|
||||
if(world.client)
|
||||
return true;
|
||||
// EntityNPCMP entity = (EntityNPCMP)player;
|
||||
if(pos != null) {
|
||||
// pos = side.getAxisDirection() == AxisDirection.NEGATIVE ? pos.offset(side) : pos;
|
||||
this.onUse(stack, player, (WorldServer)world, new Vec3(pos.getX() + hitX, pos.getY() + hitY, pos.getZ() + hitZ));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip)
|
||||
{
|
||||
tooltip.add(TextColor.DGREEN + "Reichweite: " + TextColor.GREEN + this.getRange(stack, playerIn) + " Blöcke");
|
||||
}
|
||||
|
||||
// public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
|
||||
// if(attacker.worldObj.client)
|
||||
// return true;
|
||||
// this.onUse(stack, (EntityNPCMP)attacker, (WorldServer)attacker.worldObj, new Vec3(target.posX, target.posY + target.height / 2.0, target.posZ));
|
||||
// return true;
|
||||
// }
|
||||
|
||||
public abstract int getRange(ItemStack stack, EntityNPC player);
|
||||
public abstract void onUse(ItemStack stack, EntityNPC player, WorldServer world, Vec3 vec);
|
||||
|
||||
public Transforms getTransform() {
|
||||
return Transforms.TOOL;
|
||||
}
|
||||
}
|
42
java/src/game/item/ItemWeatherToken.java
Executable file
42
java/src/game/item/ItemWeatherToken.java
Executable file
|
@ -0,0 +1,42 @@
|
|||
package game.item;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.init.SoundEvent;
|
||||
import game.world.Weather;
|
||||
import game.world.World;
|
||||
import game.world.WorldServer;
|
||||
|
||||
public class ItemWeatherToken extends ItemMagnetic {
|
||||
private final Weather weather;
|
||||
|
||||
public ItemWeatherToken(Weather weather) {
|
||||
this.weather = weather;
|
||||
this.setMaxStackSize(1);
|
||||
this.setColor(TextColor.VIOLET);
|
||||
}
|
||||
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
|
||||
{
|
||||
if(worldIn.dimension.getType().weather) {
|
||||
// if (!playerIn.creative)
|
||||
--itemStackIn.stackSize;
|
||||
worldIn.playSoundAtEntity(playerIn, SoundEvent.SPELL, 0.5F, 0.4F / (itemRand.floatv() * 0.4F + 0.8F));
|
||||
if (!worldIn.client)
|
||||
{
|
||||
WorldServer world = (WorldServer)worldIn;
|
||||
if(!world.isExterminated()) {
|
||||
world.setWeather(this.weather);
|
||||
world.resetWeather();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// playerIn.triggerAchievement(StatRegistry.objectUseStats[ItemRegistry.getIdFromItem(this)]);
|
||||
return itemStackIn;
|
||||
}
|
||||
|
||||
public String getDisplay(ItemStack stack) {
|
||||
return super.getDisplay(stack) + " (" + this.weather.getDisplay() + ")";
|
||||
}
|
||||
}
|
97
java/src/game/item/RngLoot.java
Executable file
97
java/src/game/item/RngLoot.java
Executable file
|
@ -0,0 +1,97 @@
|
|||
package game.item;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import game.inventory.IInventory;
|
||||
import game.rng.Random;
|
||||
import game.rng.RngItem;
|
||||
import game.rng.WeightedList;
|
||||
import game.tileentity.TileEntityDispenser;
|
||||
|
||||
public class RngLoot extends RngItem
|
||||
{
|
||||
private ItemStack item;
|
||||
private int minStackSize;
|
||||
private int maxStackSize;
|
||||
|
||||
public RngLoot(Item item, int amount, int min, int max, int weight)
|
||||
{
|
||||
super(weight);
|
||||
this.item = new ItemStack(item, 1, amount);
|
||||
this.minStackSize = min;
|
||||
this.maxStackSize = max;
|
||||
}
|
||||
|
||||
public RngLoot(ItemStack stack, int min, int max, int weight)
|
||||
{
|
||||
super(weight);
|
||||
this.item = stack;
|
||||
this.minStackSize = min;
|
||||
this.maxStackSize = max;
|
||||
}
|
||||
|
||||
public ItemStack getItem(Random rand) {
|
||||
if(this.item == null)
|
||||
return null;
|
||||
ItemStack stack = this.item.copy();
|
||||
stack.stackSize = this.minStackSize + rand.zrange(this.maxStackSize - this.minStackSize + 1);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static void generateChestContents(Random random, WeightedList<RngLoot> list, IInventory inv, int max)
|
||||
{
|
||||
for (int i = 0; i < max; ++i)
|
||||
{
|
||||
RngLoot loot = (RngLoot)list.pick(random);
|
||||
int j = loot.minStackSize + random.zrange(loot.maxStackSize - loot.minStackSize + 1);
|
||||
|
||||
if (loot.item.getMaxStackSize() >= j)
|
||||
{
|
||||
ItemStack itemstack1 = loot.item.copy();
|
||||
itemstack1.stackSize = j;
|
||||
inv.setInventorySlotContents(random.zrange(inv.getSizeInventory()), itemstack1);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int k = 0; k < j; ++k)
|
||||
{
|
||||
ItemStack itemstack = loot.item.copy();
|
||||
itemstack.stackSize = 1;
|
||||
inv.setInventorySlotContents(random.zrange(inv.getSizeInventory()), itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateDispenserContents(Random random, WeightedList<RngLoot> list, TileEntityDispenser dispenser, int max)
|
||||
{
|
||||
for (int i = 0; i < max; ++i)
|
||||
{
|
||||
RngLoot loot = (RngLoot)list.pick(random);
|
||||
int j = loot.minStackSize + random.zrange(loot.maxStackSize - loot.minStackSize + 1);
|
||||
|
||||
if (loot.item.getMaxStackSize() >= j)
|
||||
{
|
||||
ItemStack itemstack1 = loot.item.copy();
|
||||
itemstack1.stackSize = j;
|
||||
dispenser.setInventorySlotContents(random.zrange(dispenser.getSizeInventory()), itemstack1);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int k = 0; k < j; ++k)
|
||||
{
|
||||
ItemStack itemstack = loot.item.copy();
|
||||
itemstack.stackSize = 1;
|
||||
dispenser.setInventorySlotContents(random.zrange(dispenser.getSizeInventory()), itemstack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static WeightedList<RngLoot> addToList(WeightedList<RngLoot> items, RngLoot... add)
|
||||
{
|
||||
WeightedList<RngLoot> list = new WeightedList(items);
|
||||
Collections.addAll(list, add);
|
||||
return list;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue