Initial 1.11.2 update
This commit is contained in:
@@ -34,19 +34,20 @@ public class ContainerArcaneWorkbench extends Container {
|
||||
/** The arcane workbench tile entity associated with this container. */
|
||||
public TileEntityArcaneWorkbench tileentity;
|
||||
|
||||
public static final ResourceLocation EMPTY_SLOT_CRYSTAL = new ResourceLocation(Wizardry.MODID, "gui/empty_slot_crystal");
|
||||
public static final ResourceLocation EMPTY_SLOT_UPGRADE = new ResourceLocation(Wizardry.MODID, "gui/empty_slot_upgrade");
|
||||
public static final ResourceLocation EMPTY_SLOT_CRYSTAL = new ResourceLocation(Wizardry.MODID,
|
||||
"gui/empty_slot_crystal");
|
||||
public static final ResourceLocation EMPTY_SLOT_UPGRADE = new ResourceLocation(Wizardry.MODID,
|
||||
"gui/empty_slot_upgrade");
|
||||
|
||||
public static final int CRYSTAL_SLOT = 8;
|
||||
public static final int WAND_SLOT = 9;
|
||||
public static final int UPGRADE_SLOT = 10;
|
||||
|
||||
|
||||
private static final int[][][] SPELL_BOOK_SLOT_COORDS = {
|
||||
{{80, 22}, {121, 51}, {106, 98}, {54, 98}, {39, 51}, {-999, -999}, {-999, -999}, {-999, -999}},
|
||||
{{80, 22}, {117, 43}, {117, 85}, {80, 106}, {43, 85}, {43, 43}, {-999, -999}, {-999, -999}},
|
||||
{{80, 22}, {113, 38}, {121, 74}, {98, 102}, {62, 102}, {39, 74}, {47, 38}, {-999, -999}},
|
||||
{{80, 22}, {111, 33}, {122, 64}, {111, 95}, {80, 106}, {49, 95}, {38, 64}, {49, 33}}
|
||||
};
|
||||
{{80, 22}, {111, 33}, {122, 64}, {111, 95}, {80, 106}, {49, 95}, {38, 64}, {49, 33}}};
|
||||
|
||||
public ContainerArcaneWorkbench(IInventory inventory, TileEntityArcaneWorkbench tileentity){
|
||||
|
||||
@@ -54,12 +55,12 @@ public class ContainerArcaneWorkbench extends Container {
|
||||
|
||||
ItemStack wand = tileentity.getStackInSlot(WAND_SLOT);
|
||||
|
||||
for(int i=0; i<8; i++){
|
||||
for(int i = 0; i < 8; i++){
|
||||
this.addSlotToContainer(new SlotItemList(tileentity, i, -999, -999, 1, WizardryItems.spell_book));
|
||||
}
|
||||
|
||||
this.addSlotToContainer(new SlotItemList(tileentity, CRYSTAL_SLOT, 8, 88, 64, WizardryItems.magic_crystal))
|
||||
.setBackgroundName(EMPTY_SLOT_CRYSTAL.toString());
|
||||
.setBackgroundName(EMPTY_SLOT_CRYSTAL.toString());
|
||||
|
||||
this.addSlotToContainer(new SlotWandArmour(tileentity, WAND_SLOT, 80, 64, this));
|
||||
|
||||
@@ -68,7 +69,7 @@ public class ContainerArcaneWorkbench extends Container {
|
||||
upgrades.add(WizardryItems.armour_upgrade);
|
||||
|
||||
this.addSlotToContainer(new SlotItemList(tileentity, UPGRADE_SLOT, 8, 106, 1, upgrades.toArray(new Item[0])))
|
||||
.setBackgroundName(EMPTY_SLOT_UPGRADE.toString());
|
||||
.setBackgroundName(EMPTY_SLOT_UPGRADE.toString());
|
||||
|
||||
for(int x = 0; x < 9; x++){
|
||||
this.addSlotToContainer(new Slot(inventory, x, 8 + x * 18, 196));
|
||||
@@ -85,7 +86,7 @@ public class ContainerArcaneWorkbench extends Container {
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player){
|
||||
return this.tileentity.isUseableByPlayer(player);
|
||||
return this.tileentity.isUsableByPlayer(player);
|
||||
}
|
||||
|
||||
/** Called from the central wand/armour slot when its item is changed or removed. */
|
||||
@@ -94,21 +95,21 @@ public class ContainerArcaneWorkbench extends Container {
|
||||
|
||||
if(slotNumber == WAND_SLOT){
|
||||
|
||||
if(stack == null || (!(stack.getItem() instanceof ItemWand) && stack.getItem() != WizardryItems.blank_scroll)){
|
||||
if(!(stack.getItem() instanceof ItemWand) && stack.getItem() != WizardryItems.blank_scroll){
|
||||
// If the stack has been removed
|
||||
for(int i=0; i<CRYSTAL_SLOT; i++){
|
||||
for(int i = 0; i < CRYSTAL_SLOT; i++){
|
||||
Slot slot1 = this.getSlot(i);
|
||||
// 'Removes' the slot from the container (moves it off the screen)
|
||||
slot1.xDisplayPosition = -100;
|
||||
slot1.yDisplayPosition = -100;
|
||||
slot1.xPos = -100;
|
||||
slot1.yPos = -100;
|
||||
|
||||
ItemStack stack1 = slot1.getStack();
|
||||
// This doesn't cause an infinite loop because slot i can never be a SlotWandArmour. In effect, it's
|
||||
// exactly the same as shift-clicking the slot, so why re-invent the wheel?
|
||||
ItemStack remainder = this.transferStackInSlot(player, i);
|
||||
|
||||
if(remainder == null && stack1 != null){
|
||||
slot1.putStack(null);
|
||||
if(remainder == ItemStack.EMPTY && stack1 != ItemStack.EMPTY){
|
||||
slot1.putStack(ItemStack.EMPTY);
|
||||
// The second parameter is never used...
|
||||
if(player != null) player.dropItem(stack1, false);
|
||||
}
|
||||
@@ -119,24 +120,25 @@ public class ContainerArcaneWorkbench extends Container {
|
||||
if(stack.getItem() == WizardryItems.blank_scroll){
|
||||
// If a blank scroll is added
|
||||
// The first slot is shown
|
||||
this.getSlot(0).xDisplayPosition = SPELL_BOOK_SLOT_COORDS[0][0][0];
|
||||
this.getSlot(0).yDisplayPosition = SPELL_BOOK_SLOT_COORDS[0][0][1];
|
||||
this.getSlot(0).xPos = SPELL_BOOK_SLOT_COORDS[0][0][0];
|
||||
this.getSlot(0).yPos = SPELL_BOOK_SLOT_COORDS[0][0][1];
|
||||
|
||||
// The rest of the slots are hidden
|
||||
for(int i=1; i<CRYSTAL_SLOT; i++){
|
||||
for(int i = 1; i < CRYSTAL_SLOT; i++){
|
||||
|
||||
Slot slot1 = this.getSlot(i);
|
||||
|
||||
slot1.xDisplayPosition = -100;
|
||||
slot1.yDisplayPosition = -100;
|
||||
slot1.xPos = -100;
|
||||
slot1.yPos = -100;
|
||||
|
||||
ItemStack stack1 = slot1.getStack();
|
||||
// This doesn't cause an infinite loop because slot i can never be a SlotWandArmour. In effect, it's
|
||||
// This doesn't cause an infinite loop because slot i can never be a SlotWandArmour. In effect,
|
||||
// it's
|
||||
// exactly the same as shift-clicking the slot, so why re-invent the wheel?
|
||||
ItemStack remainder = this.transferStackInSlot(player, i);
|
||||
|
||||
if(remainder == null && stack1 != null){
|
||||
slot1.putStack(null);
|
||||
if(remainder == ItemStack.EMPTY && stack1 != ItemStack.EMPTY){
|
||||
slot1.putStack(ItemStack.EMPTY);
|
||||
// The second parameter is never used...
|
||||
if(player != null) player.dropItem(stack1, false);
|
||||
}
|
||||
@@ -144,25 +146,26 @@ public class ContainerArcaneWorkbench extends Container {
|
||||
|
||||
}else{
|
||||
|
||||
for(int i=0; i<CRYSTAL_SLOT; i++){
|
||||
for(int i = 0; i < CRYSTAL_SLOT; i++){
|
||||
|
||||
int n = WandHelper.getUpgradeLevel(stack, WizardryItems.attunement_upgrade);
|
||||
int[] coords = SPELL_BOOK_SLOT_COORDS[n][i];
|
||||
|
||||
Slot slot1 = this.getSlot(i);
|
||||
// Puts the slot back in the correct position
|
||||
slot1.xDisplayPosition = coords[0];
|
||||
slot1.yDisplayPosition = coords[1];
|
||||
slot1.xPos = coords[0];
|
||||
slot1.yPos = coords[1];
|
||||
|
||||
if(slot1.xDisplayPosition < 0 || slot1.yDisplayPosition < 0){
|
||||
if(slot1.xPos < 0 || slot1.yPos < 0){
|
||||
|
||||
ItemStack stack1 = slot1.getStack();
|
||||
// This doesn't cause an infinite loop because slot i can never be a SlotWandArmour. In effect, it's
|
||||
// This doesn't cause an infinite loop because slot i can never be a SlotWandArmour. In
|
||||
// effect, it's
|
||||
// exactly the same as shift-clicking the slot, so why re-invent the wheel?
|
||||
ItemStack remainder = this.transferStackInSlot(player, i);
|
||||
|
||||
if(remainder == null && stack1 != null){
|
||||
slot1.putStack(null);
|
||||
if(remainder == ItemStack.EMPTY && stack1 != ItemStack.EMPTY){
|
||||
slot1.putStack(ItemStack.EMPTY);
|
||||
// The second parameter is never used...
|
||||
if(player != null) player.dropItem(stack1, false);
|
||||
}
|
||||
@@ -178,21 +181,20 @@ public class ContainerArcaneWorkbench extends Container {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int clickedSlotId)
|
||||
{
|
||||
ItemStack remainder = null;
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int clickedSlotId){
|
||||
|
||||
ItemStack remainder = ItemStack.EMPTY;
|
||||
Slot slot = (Slot)this.inventorySlots.get(clickedSlotId);
|
||||
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
if(slot != null && slot.getHasStack()){
|
||||
ItemStack stack = slot.getStack(); // The stack that was there originally
|
||||
remainder = stack.copy(); // A copy of that stack
|
||||
|
||||
// Workbench -> inventory
|
||||
if(clickedSlotId <= UPGRADE_SLOT){
|
||||
// Tries to move the stack into the player's inventory. If this fails...
|
||||
if (!this.mergeItemStack(stack, UPGRADE_SLOT + 1, this.inventorySlots.size(), true)){
|
||||
return null; // ...nothing else happens.
|
||||
if(!this.mergeItemStack(stack, UPGRADE_SLOT + 1, this.inventorySlots.size(), true)){
|
||||
return ItemStack.EMPTY; // ...nothing else happens.
|
||||
}
|
||||
}
|
||||
// Inventory -> workbench
|
||||
@@ -203,48 +205,39 @@ public class ContainerArcaneWorkbench extends Container {
|
||||
|
||||
if(stack.getItem() instanceof ItemSpellBook){
|
||||
minSlotId = 0;
|
||||
maxSlotId = CRYSTAL_SLOT-1;
|
||||
}
|
||||
else if(stack.getItem() == WizardryItems.magic_crystal){
|
||||
maxSlotId = CRYSTAL_SLOT - 1;
|
||||
}else if(stack.getItem() == WizardryItems.magic_crystal){
|
||||
minSlotId = CRYSTAL_SLOT;
|
||||
maxSlotId = CRYSTAL_SLOT;
|
||||
}
|
||||
else if(stack.getItem() instanceof ItemWand || stack.getItem() instanceof ItemWizardArmour
|
||||
}else if(stack.getItem() instanceof ItemWand || stack.getItem() instanceof ItemWizardArmour
|
||||
|| stack.getItem() == WizardryItems.blank_scroll){
|
||||
minSlotId = WAND_SLOT;
|
||||
maxSlotId = WAND_SLOT;
|
||||
}
|
||||
else if(stack.getItem() instanceof ItemArcaneTome
|
||||
|| stack.getItem() instanceof ItemArmourUpgrade
|
||||
}else if(stack.getItem() instanceof ItemArcaneTome || stack.getItem() instanceof ItemArmourUpgrade
|
||||
|| WandHelper.isWandUpgrade(stack.getItem())){
|
||||
minSlotId = UPGRADE_SLOT;
|
||||
maxSlotId = UPGRADE_SLOT;
|
||||
}
|
||||
else{
|
||||
return null; // If none of the above cases were true, then the item won't fit in the workbench.
|
||||
}else{
|
||||
return ItemStack.EMPTY; // If none of the above cases were true, then the item won't fit in the
|
||||
// workbench.
|
||||
}
|
||||
|
||||
if(!this.mergeItemStack(stack, minSlotId, maxSlotId + 1, false))
|
||||
{
|
||||
return null;
|
||||
if(!this.mergeItemStack(stack, minSlotId, maxSlotId + 1, false)){
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(stack.getCount() == 0){
|
||||
slot.putStack(ItemStack.EMPTY);
|
||||
}else{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (stack.stackSize == remainder.stackSize)
|
||||
{
|
||||
return null;
|
||||
if(stack.getCount() == remainder.getCount()){
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(player, stack);
|
||||
slot.onTake(player, stack);
|
||||
}
|
||||
|
||||
return remainder;
|
||||
@@ -252,11 +245,11 @@ public class ContainerArcaneWorkbench extends Container {
|
||||
|
||||
// Overridden to stop stacks merging into 'removed' slots.
|
||||
@Override
|
||||
protected boolean mergeItemStack(ItemStack stack, int minSlotID, int maxSlotID, boolean p_75135_4_) {
|
||||
protected boolean mergeItemStack(ItemStack stack, int minSlotID, int maxSlotID, boolean p_75135_4_){
|
||||
|
||||
for(int i=minSlotID; i<maxSlotID; i++){
|
||||
//System.out.println(this.getSlot(i).xDisplayPosition);
|
||||
if(this.getSlot(i).xDisplayPosition >= 0 && this.getSlot(i).yDisplayPosition >= 0 && !this.getSlot(i).getHasStack()){
|
||||
for(int i = minSlotID; i < maxSlotID; i++){
|
||||
// System.out.println(this.getSlot(i).xDisplayPosition);
|
||||
if(this.getSlot(i).xPos >= 0 && this.getSlot(i).yPos >= 0 && !this.getSlot(i).getHasStack()){
|
||||
return super.mergeItemStack(stack, minSlotID, maxSlotID, p_75135_4_);
|
||||
}
|
||||
}
|
||||
@@ -264,15 +257,17 @@ public class ContainerArcaneWorkbench extends Container {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Called (via {@link electroblob.wizardry.packet.PacketControlInput PacketControlInput}) when the apply button
|
||||
* in the arcane workbench GUI is pressed. */
|
||||
/**
|
||||
* Called (via {@link electroblob.wizardry.packet.PacketControlInput PacketControlInput}) when the apply button in
|
||||
* the arcane workbench GUI is pressed.
|
||||
*/
|
||||
// All operations on the items contained in the inventory simply call the corresponding methods in the tileentity.
|
||||
// As of 2.1, for the sake of events and neatness of code, this was moved here from TileEntityArcaneWorkbench.
|
||||
public void onApplyButtonPressed(EntityPlayer player){
|
||||
|
||||
ItemStack wand = this.getSlot(WAND_SLOT).getStack();
|
||||
ItemStack[] spellBooks = new ItemStack[CRYSTAL_SLOT];
|
||||
for(int i=0; i<spellBooks.length; i++){
|
||||
for(int i = 0; i < spellBooks.length; i++){
|
||||
spellBooks[i] = this.getSlot(i).getStack();
|
||||
}
|
||||
ItemStack crystals = this.getSlot(CRYSTAL_SLOT).getStack();
|
||||
@@ -281,105 +276,108 @@ public class ContainerArcaneWorkbench extends Container {
|
||||
if(MinecraftForge.EVENT_BUS.post(new SpellBindEvent(player, this))) return;
|
||||
|
||||
// Since the workbench now accepts armour as well as wands, this check is needed.
|
||||
if(wand != null && wand.getItem() instanceof ItemWand){
|
||||
if(wand.getItem() instanceof ItemWand){
|
||||
|
||||
// Upgrades wand if necessary. Damage is copied, preserving remaining durability,
|
||||
// and also the entire NBT tag compound.
|
||||
if(upgrade != null){
|
||||
if(upgrade.getItem() == WizardryItems.arcane_tome){
|
||||
|
||||
if(upgrade.getItem() == WizardryItems.arcane_tome){
|
||||
ItemStack newWand;
|
||||
|
||||
ItemStack newWand;
|
||||
switch(Tier.values()[upgrade.getItemDamage()]){
|
||||
|
||||
switch(Tier.values()[upgrade.getItemDamage()]){
|
||||
case APPRENTICE:
|
||||
if(((ItemWand)wand.getItem()).tier == Tier.BASIC){
|
||||
newWand = new ItemStack(WizardryUtilities.getWand(Tier.values()[upgrade.getItemDamage()],
|
||||
((ItemWand)wand.getItem()).element));
|
||||
newWand.setTagCompound(wand.getTagCompound());
|
||||
// This needs to be done after copying the tag compound so the max damage for the new wand
|
||||
// takes storage
|
||||
// upgrades into account.
|
||||
newWand.setItemDamage(newWand.getMaxDamage() - (wand.getMaxDamage() - wand.getItemDamage()));
|
||||
this.putStackInSlot(WAND_SLOT, newWand);
|
||||
this.putStackInSlot(UPGRADE_SLOT, ItemStack.EMPTY);
|
||||
player.addStat(WizardryAchievements.apprentice, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case APPRENTICE:
|
||||
if(((ItemWand)wand.getItem()).tier == Tier.BASIC){
|
||||
newWand = new ItemStack(WizardryUtilities.getWand(Tier.values()[upgrade.getItemDamage()], ((ItemWand)wand.getItem()).element));
|
||||
newWand.setTagCompound(wand.getTagCompound());
|
||||
// This needs to be done after copying the tag compound so the max damage for the new wand takes storage
|
||||
// upgrades into account.
|
||||
newWand.setItemDamage(newWand.getMaxDamage() - (wand.getMaxDamage() - wand.getItemDamage()));
|
||||
this.putStackInSlot(WAND_SLOT, newWand);
|
||||
this.putStackInSlot(UPGRADE_SLOT, null);
|
||||
player.addStat(WizardryAchievements.apprentice, 1);
|
||||
case ADVANCED:
|
||||
if(((ItemWand)wand.getItem()).tier == Tier.APPRENTICE){
|
||||
newWand = new ItemStack(WizardryUtilities.getWand(Tier.values()[upgrade.getItemDamage()],
|
||||
((ItemWand)wand.getItem()).element));
|
||||
newWand.setTagCompound(wand.getTagCompound());
|
||||
newWand.setItemDamage(newWand.getMaxDamage() - (wand.getMaxDamage() - wand.getItemDamage()));
|
||||
this.putStackInSlot(WAND_SLOT, newWand);
|
||||
this.putStackInSlot(UPGRADE_SLOT, ItemStack.EMPTY);
|
||||
}
|
||||
break;
|
||||
|
||||
case MASTER:
|
||||
if(((ItemWand)wand.getItem()).tier == Tier.ADVANCED){
|
||||
newWand = new ItemStack(WizardryUtilities.getWand(Tier.values()[upgrade.getItemDamage()],
|
||||
((ItemWand)wand.getItem()).element));
|
||||
newWand.setTagCompound(wand.getTagCompound());
|
||||
newWand.setItemDamage(newWand.getMaxDamage() - (wand.getMaxDamage() - wand.getItemDamage()));
|
||||
this.putStackInSlot(WAND_SLOT, newWand);
|
||||
this.putStackInSlot(UPGRADE_SLOT, ItemStack.EMPTY);
|
||||
player.addStat(WizardryAchievements.master, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// This needs to happen so the charging works on the new wand, not the old one.
|
||||
wand = this.getSlot(WAND_SLOT).getStack();
|
||||
|
||||
}else{
|
||||
|
||||
// Special upgrades
|
||||
|
||||
// Used to preserve existing mana when upgrading storage rather than creating free mana.
|
||||
int prevMana = wand.getMaxDamage() - wand.getItemDamage();
|
||||
|
||||
if(WandHelper.getTotalUpgrades(wand) < ((ItemWand)wand.getItem()).tier.upgradeLimit
|
||||
&& WandHelper.getUpgradeLevel(wand, upgrade.getItem()) < Constants.UPGRADE_STACK_LIMIT){
|
||||
|
||||
WandHelper.applyUpgrade(wand, upgrade.getItem());
|
||||
|
||||
// Special behaviours for specific upgrades
|
||||
if(upgrade.getItem() == WizardryItems.storage_upgrade){
|
||||
wand.setItemDamage(wand.getMaxDamage() - prevMana);
|
||||
}
|
||||
if(upgrade.getItem() == WizardryItems.attunement_upgrade){
|
||||
|
||||
Spell[] spells = WandHelper.getSpells(wand);
|
||||
Spell[] newSpells = new Spell[5
|
||||
+ WandHelper.getUpgradeLevel(wand, WizardryItems.attunement_upgrade)];
|
||||
|
||||
for(int i = 0; i < newSpells.length; i++){
|
||||
// Prevents both NPEs and AIOOBEs
|
||||
newSpells[i] = i < spells.length && spells[i] != null ? spells[i] : Spells.none;
|
||||
}
|
||||
break;
|
||||
|
||||
case ADVANCED:
|
||||
if(((ItemWand)wand.getItem()).tier == Tier.APPRENTICE){
|
||||
newWand = new ItemStack(WizardryUtilities.getWand(Tier.values()[upgrade.getItemDamage()], ((ItemWand)wand.getItem()).element));
|
||||
newWand.setTagCompound(wand.getTagCompound());
|
||||
newWand.setItemDamage(newWand.getMaxDamage() - (wand.getMaxDamage() - wand.getItemDamage()));
|
||||
this.putStackInSlot(WAND_SLOT, newWand);
|
||||
this.putStackInSlot(UPGRADE_SLOT, null);
|
||||
WandHelper.setSpells(wand, newSpells);
|
||||
|
||||
int[] cooldown = WandHelper.getCooldowns(wand);
|
||||
int[] newCooldown = new int[5
|
||||
+ WandHelper.getUpgradeLevel(wand, WizardryItems.attunement_upgrade)];
|
||||
|
||||
if(cooldown.length > 0){
|
||||
for(int i = 0; i < cooldown.length; i++){
|
||||
newCooldown[i] = cooldown[i];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MASTER:
|
||||
if(((ItemWand)wand.getItem()).tier == Tier.ADVANCED){
|
||||
newWand = new ItemStack(WizardryUtilities.getWand(Tier.values()[upgrade.getItemDamage()], ((ItemWand)wand.getItem()).element));
|
||||
newWand.setTagCompound(wand.getTagCompound());
|
||||
newWand.setItemDamage(newWand.getMaxDamage() - (wand.getMaxDamage() - wand.getItemDamage()));
|
||||
this.putStackInSlot(WAND_SLOT, newWand);
|
||||
this.putStackInSlot(UPGRADE_SLOT, null);
|
||||
player.addStat(WizardryAchievements.master, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
WandHelper.setCooldowns(wand, newCooldown);
|
||||
}
|
||||
|
||||
// This needs to happen so the charging works on the new wand, not the old one.
|
||||
wand = this.getSlot(WAND_SLOT).getStack();
|
||||
this.getSlot(UPGRADE_SLOT).decrStackSize(1);
|
||||
player.addStat(WizardryAchievements.special_upgrade, 1);
|
||||
|
||||
}else{
|
||||
|
||||
// Special upgrades
|
||||
|
||||
// Used to preserve existing mana when upgrading storage rather than creating free mana.
|
||||
int prevMana = wand.getMaxDamage() - wand.getItemDamage();
|
||||
|
||||
if(WandHelper.getTotalUpgrades(wand) < ((ItemWand)wand.getItem()).tier.upgradeLimit
|
||||
&& WandHelper.getUpgradeLevel(wand, upgrade.getItem()) < Constants.UPGRADE_STACK_LIMIT){
|
||||
|
||||
WandHelper.applyUpgrade(wand, upgrade.getItem());
|
||||
|
||||
// Special behaviours for specific upgrades
|
||||
if(upgrade.getItem() == WizardryItems.storage_upgrade){
|
||||
wand.setItemDamage(wand.getMaxDamage() - prevMana);
|
||||
}
|
||||
if(upgrade.getItem() == WizardryItems.attunement_upgrade){
|
||||
|
||||
Spell[] spells = WandHelper.getSpells(wand);
|
||||
Spell[] newSpells = new Spell[5 + WandHelper.getUpgradeLevel(wand, WizardryItems.attunement_upgrade)];
|
||||
|
||||
for(int i=0; i<newSpells.length; i++){
|
||||
// Prevents both NPEs and AIOOBEs
|
||||
newSpells[i] = i < spells.length && spells[i] != null ? spells[i] : Spells.none;
|
||||
}
|
||||
|
||||
WandHelper.setSpells(wand, newSpells);
|
||||
|
||||
int[] cooldown = WandHelper.getCooldowns(wand);
|
||||
int[] newCooldown = new int[5 + WandHelper.getUpgradeLevel(wand, WizardryItems.attunement_upgrade)];
|
||||
|
||||
if(cooldown.length > 0){
|
||||
for(int i=0; i<cooldown.length; i++){
|
||||
newCooldown[i] = cooldown[i];
|
||||
}
|
||||
}
|
||||
|
||||
WandHelper.setCooldowns(wand, newCooldown);
|
||||
}
|
||||
|
||||
this.getSlot(UPGRADE_SLOT).decrStackSize(1);
|
||||
player.addStat(WizardryAchievements.special_upgrade, 1);
|
||||
|
||||
if(WandHelper.getTotalUpgrades(wand) == Tier.MASTER.upgradeLimit){
|
||||
player.addStat(WizardryAchievements.max_out_wand, 1);
|
||||
}
|
||||
if(WandHelper.getTotalUpgrades(wand) == Tier.MASTER.upgradeLimit){
|
||||
player.addStat(WizardryAchievements.max_out_wand, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -394,65 +392,72 @@ public class ContainerArcaneWorkbench extends Container {
|
||||
// 5 here because if the spell array doesn't exist, the wand can't possibly have attunement upgrades
|
||||
spells = new Spell[5];
|
||||
}
|
||||
for(int i=0; i<spells.length; i++){
|
||||
if(spellBooks[i] != null && !(Spell.get(spellBooks[i].getItemDamage()).tier.level > ((ItemWand)wand.getItem()).tier.level)){
|
||||
for(int i = 0; i < spells.length; i++){
|
||||
if(spellBooks[i] != ItemStack.EMPTY && !(Spell
|
||||
.get(spellBooks[i].getItemDamage()).tier.level > ((ItemWand)wand.getItem()).tier.level)){
|
||||
spells[i] = Spell.get(spellBooks[i].getItemDamage());
|
||||
}
|
||||
}
|
||||
WandHelper.setSpells(wand, spells);
|
||||
|
||||
// Charges wand by appropriate amount
|
||||
if(crystals != null){
|
||||
if(crystals != ItemStack.EMPTY){
|
||||
int chargeDepleted = wand.getItemDamage();
|
||||
//System.out.println("Charge depleted: " + chargeDepleted);
|
||||
//System.out.println("Crystals found: " + crystals.stackSize);
|
||||
if(crystals.stackSize * Constants.MANA_PER_CRYSTAL < chargeDepleted){
|
||||
//System.out.println("charging");
|
||||
wand.setItemDamage(chargeDepleted - crystals.stackSize * Constants.MANA_PER_CRYSTAL);
|
||||
this.getSlot(CRYSTAL_SLOT).decrStackSize(crystals.stackSize);
|
||||
// System.out.println("Charge depleted: " + chargeDepleted);
|
||||
// System.out.println("Crystals found: " + crystals.getCount());
|
||||
if(crystals.getCount() * Constants.MANA_PER_CRYSTAL < chargeDepleted){
|
||||
// System.out.println("charging");
|
||||
wand.setItemDamage(chargeDepleted - crystals.getCount() * Constants.MANA_PER_CRYSTAL);
|
||||
this.getSlot(CRYSTAL_SLOT).decrStackSize(crystals.getCount());
|
||||
}else if(chargeDepleted != 0){
|
||||
//System.out.println((int)Math.ceil(((double)chargeDepleted)/50));
|
||||
this.getSlot(CRYSTAL_SLOT).decrStackSize((int)Math.ceil(((double)chargeDepleted)/Constants.MANA_PER_CRYSTAL));
|
||||
// System.out.println((int)Math.ceil(((double)chargeDepleted)/50));
|
||||
this.getSlot(CRYSTAL_SLOT)
|
||||
.decrStackSize((int)Math.ceil(((double)chargeDepleted) / Constants.MANA_PER_CRYSTAL));
|
||||
wand.setItemDamage(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Armour
|
||||
else if(wand != null && wand.getItem() instanceof ItemWizardArmour){
|
||||
else if(wand.getItem() instanceof ItemWizardArmour){
|
||||
// Applies legendary upgrade
|
||||
if(upgrade != null && upgrade.getItem() == WizardryItems.armour_upgrade){
|
||||
if(upgrade.getItem() == WizardryItems.armour_upgrade){
|
||||
if(!wand.hasTagCompound()){
|
||||
wand.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
if(!wand.getTagCompound().hasKey("legendary")){
|
||||
wand.getTagCompound().setBoolean("legendary", true);
|
||||
this.putStackInSlot(UPGRADE_SLOT, null);
|
||||
this.putStackInSlot(UPGRADE_SLOT, ItemStack.EMPTY);
|
||||
player.addStat(WizardryAchievements.legendary);
|
||||
}
|
||||
}
|
||||
// Charges armour by appropriate amount
|
||||
if(crystals != null){
|
||||
if(crystals != ItemStack.EMPTY){
|
||||
int chargeDepleted = wand.getItemDamage();
|
||||
if(crystals.stackSize * Constants.MANA_PER_CRYSTAL < chargeDepleted){
|
||||
wand.setItemDamage(chargeDepleted - crystals.stackSize * Constants.MANA_PER_CRYSTAL);
|
||||
this.getSlot(CRYSTAL_SLOT).decrStackSize(crystals.stackSize);
|
||||
if(crystals.getCount() * Constants.MANA_PER_CRYSTAL < chargeDepleted){
|
||||
wand.setItemDamage(chargeDepleted - crystals.getCount() * Constants.MANA_PER_CRYSTAL);
|
||||
this.getSlot(CRYSTAL_SLOT).decrStackSize(crystals.getCount());
|
||||
}else if(chargeDepleted != 0){
|
||||
this.getSlot(CRYSTAL_SLOT).decrStackSize((int)Math.ceil(((double)chargeDepleted)/Constants.MANA_PER_CRYSTAL));
|
||||
this.getSlot(CRYSTAL_SLOT)
|
||||
.decrStackSize((int)Math.ceil(((double)chargeDepleted) / Constants.MANA_PER_CRYSTAL));
|
||||
wand.setItemDamage(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Scrolls
|
||||
else if(wand != null && wand.getItem() == WizardryItems.blank_scroll){
|
||||
// Spells can only be bound to scrolls if the player has already cast them (prevents casting of master spells without getting a master wand)
|
||||
// This restriction does not apply in creative mode
|
||||
if(spellBooks[0] != null && (player.capabilities.isCreativeMode || (WizardData.get(player) != null
|
||||
&& WizardData.get(player).hasSpellBeenDiscovered(Spell.get(spellBooks[0].getItemDamage()))))
|
||||
&& crystals != null && crystals.stackSize * Constants.MANA_PER_CRYSTAL > Spell.get(spellBooks[0].getItemDamage()).cost){
|
||||
|
||||
this.getSlot(CRYSTAL_SLOT).decrStackSize((int)Math.ceil(((double)Spell.get(spellBooks[0].getItemDamage()).cost)/Constants.MANA_PER_CRYSTAL));
|
||||
// Scrolls
|
||||
else if(wand.getItem() == WizardryItems.blank_scroll){
|
||||
// Spells can only be bound to scrolls if the player has already cast them (prevents casting of master
|
||||
// spells without getting a master wand)
|
||||
// This restriction does not apply in creative mode
|
||||
if(spellBooks[0] != ItemStack.EMPTY
|
||||
&& (player.capabilities.isCreativeMode || (WizardData.get(player) != null
|
||||
&& WizardData.get(player).hasSpellBeenDiscovered(Spell.get(spellBooks[0].getItemDamage()))))
|
||||
&& crystals != ItemStack.EMPTY && crystals.getCount()
|
||||
* Constants.MANA_PER_CRYSTAL > Spell.get(spellBooks[0].getItemDamage()).cost){
|
||||
|
||||
this.getSlot(CRYSTAL_SLOT).decrStackSize((int)Math
|
||||
.ceil(((double)Spell.get(spellBooks[0].getItemDamage()).cost) / Constants.MANA_PER_CRYSTAL));
|
||||
this.putStackInSlot(WAND_SLOT, new ItemStack(WizardryItems.scroll, 1, spellBooks[0].getItemDamage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,16 +8,15 @@ import net.minecraft.world.World;
|
||||
|
||||
public class ContainerPortableWorkbench extends ContainerWorkbench {
|
||||
|
||||
public ContainerPortableWorkbench(InventoryPlayer inventory, World world, BlockPos pos) {
|
||||
|
||||
public ContainerPortableWorkbench(InventoryPlayer inventory, World world, BlockPos pos){
|
||||
|
||||
super(inventory, world, pos);
|
||||
}
|
||||
|
||||
// Overriden to stop the crafting gui from closing when there is no crafting table.
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityPlayer player){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,30 +7,31 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Simple extension of {@link Slot} which only accepts items from an array defined in the constructor.
|
||||
*
|
||||
* @author Electroblob
|
||||
* @since Wizardry 1.0
|
||||
*/
|
||||
public class SlotItemList extends Slot {
|
||||
|
||||
|
||||
private Item[] items;
|
||||
private int stackLimit;
|
||||
|
||||
public SlotItemList(IInventory par1iInventory, int index, int x, int y, int stackLimit, Item... allowedItems) {
|
||||
public SlotItemList(IInventory par1iInventory, int index, int x, int y, int stackLimit, Item... allowedItems){
|
||||
super(par1iInventory, index, x, y);
|
||||
this.items = allowedItems;
|
||||
this.stackLimit = stackLimit;
|
||||
}
|
||||
|
||||
|
||||
public int getSlotStackLimit(){
|
||||
return stackLimit;
|
||||
}
|
||||
|
||||
public boolean isItemValid(ItemStack par1ItemStack){
|
||||
for(int i=0; i<items.length; i++){
|
||||
if(par1ItemStack != null && (par1ItemStack.getItem() == this.items[i])){
|
||||
return stackLimit;
|
||||
}
|
||||
|
||||
public boolean isItemValid(ItemStack stack){
|
||||
for(int i = 0; i < items.length; i++){
|
||||
if(stack.getItem() == this.items[i]){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,40 +10,39 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* The central wand/armour/scroll slot in the arcane workbench GUI.
|
||||
*
|
||||
* @author Electroblob
|
||||
* @since Wizardry 1.0
|
||||
*/
|
||||
public class SlotWandArmour extends Slot {
|
||||
|
||||
|
||||
private ContainerArcaneWorkbench container;
|
||||
|
||||
public SlotWandArmour(IInventory par1iInventory, int index, int x, int y, ContainerArcaneWorkbench container) {
|
||||
public SlotWandArmour(IInventory par1iInventory, int index, int x, int y, ContainerArcaneWorkbench container){
|
||||
super(par1iInventory, index, x, y);
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack stack){
|
||||
super.putStack(stack);
|
||||
this.container.onSlotChanged(slotNumber, stack, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer player, ItemStack stack) {
|
||||
super.onPickupFromSlot(player, stack);
|
||||
this.container.onSlotChanged(slotNumber, null, player);
|
||||
public ItemStack onTake(EntityPlayer player, ItemStack stack){
|
||||
this.container.onSlotChanged(slotNumber, ItemStack.EMPTY, player);
|
||||
return super.onTake(player, stack);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getSlotStackLimit()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int getSlotStackLimit(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemstack){
|
||||
return itemstack != null && (itemstack.getItem() instanceof ItemWand
|
||||
|| itemstack.getItem() instanceof ItemWizardArmour
|
||||
return (itemstack.getItem() instanceof ItemWand || itemstack.getItem() instanceof ItemWizardArmour
|
||||
|| itemstack.getItem() == WizardryItems.blank_scroll);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
@@ -26,7 +27,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class TileEntityArcaneWorkbench extends TileEntity implements IInventory, ITickable {
|
||||
|
||||
private ItemStack[] inv;
|
||||
private NonNullList<ItemStack> inventory;
|
||||
/** Controls the rotation of the rune. */
|
||||
public float timer = 0;
|
||||
/** Controls the change of yOffset. */
|
||||
@@ -35,19 +36,19 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory,
|
||||
public int yOffset = 300;
|
||||
|
||||
public TileEntityArcaneWorkbench(){
|
||||
inv = new ItemStack[ContainerArcaneWorkbench.UPGRADE_SLOT + 1];
|
||||
inventory = NonNullList.withSize(ContainerArcaneWorkbench.UPGRADE_SLOT + 1, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onLoad(){
|
||||
timer = 0;
|
||||
yTimer = 0;
|
||||
yOffset = 300;
|
||||
}
|
||||
|
||||
|
||||
/** Called to manually sync the tile entity with clients. */
|
||||
public void sync(){
|
||||
this.worldObj.notifyBlockUpdate(pos, worldObj.getBlockState(pos), worldObj.getBlockState(pos), 3);
|
||||
this.world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,14 +57,15 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory,
|
||||
ItemStack itemstack = this.getStackInSlot(ContainerArcaneWorkbench.WAND_SLOT);
|
||||
|
||||
// Decrements wand damage (increases mana) every 1.5 seconds if it has a condenser upgrade
|
||||
if(itemstack != null && itemstack.getItem() instanceof ItemWand && !this.worldObj.isRemote && itemstack.isItemDamaged()
|
||||
&& this.worldObj.getWorldTime() % electroblob.wizardry.constants.Constants.CONDENSER_TICK_INTERVAL == 0){
|
||||
if(itemstack.getItem() instanceof ItemWand && !this.world.isRemote && itemstack.isItemDamaged()
|
||||
&& this.world.getWorldTime() % electroblob.wizardry.constants.Constants.CONDENSER_TICK_INTERVAL == 0){
|
||||
// If the upgrade level is 0, this does nothing anyway.
|
||||
itemstack.setItemDamage(itemstack.getItemDamage() - WandHelper.getUpgradeLevel(itemstack, WizardryItems.condenser_upgrade));
|
||||
itemstack.setItemDamage(
|
||||
itemstack.getItemDamage() - WandHelper.getUpgradeLevel(itemstack, WizardryItems.condenser_upgrade));
|
||||
}
|
||||
|
||||
// The server doesn't care what these are, and there's no need for them to be synced or saved.
|
||||
if(this.worldObj.isRemote){
|
||||
if(this.world.isRemote){
|
||||
if(timer < 359){
|
||||
timer++;
|
||||
}else{
|
||||
@@ -79,25 +81,25 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory,
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inv.length;
|
||||
public int getSizeInventory(){
|
||||
return inventory.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return inv[slot];
|
||||
public ItemStack getStackInSlot(int slot){
|
||||
return inventory.get(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amt) {
|
||||
public ItemStack decrStackSize(int slot, int amt){
|
||||
ItemStack stack = getStackInSlot(slot);
|
||||
if (stack != null) {
|
||||
if (stack.stackSize <= amt) {
|
||||
setInventorySlotContents(slot, null);
|
||||
} else {
|
||||
if(!stack.isEmpty()){
|
||||
if(stack.getCount() <= amt){
|
||||
setInventorySlotContents(slot, ItemStack.EMPTY);
|
||||
}else{
|
||||
stack = stack.splitStack(amt);
|
||||
if (stack.stackSize == 0) {
|
||||
setInventorySlotContents(slot, null);
|
||||
if(stack.getCount() == 0){
|
||||
setInventorySlotContents(slot, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,56 +107,56 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory,
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int slot) {
|
||||
public ItemStack removeStackFromSlot(int slot){
|
||||
ItemStack stack = getStackInSlot(slot);
|
||||
if (stack != null) {
|
||||
setInventorySlotContents(slot, null);
|
||||
if(!stack.isEmpty()){
|
||||
setInventorySlotContents(slot, ItemStack.EMPTY);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
inv[slot] = stack;
|
||||
if (stack != null && stack.stackSize > getInventoryStackLimit()) {
|
||||
stack.stackSize = getInventoryStackLimit();
|
||||
}
|
||||
public void setInventorySlotContents(int slot, ItemStack stack){
|
||||
inventory.set(slot, stack);
|
||||
if(!stack.isEmpty() && stack.getCount() > getInventoryStackLimit()){
|
||||
stack.setCount(getInventoryStackLimit());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
public String getName(){
|
||||
return "container.wizardry:arcane_workbench";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
public boolean hasCustomName(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
public int getInventoryStackLimit(){
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return worldObj.getTileEntity(pos) == this && player.getDistanceSqToCenter(pos) < 64;
|
||||
public boolean isUsableByPlayer(EntityPlayer player){
|
||||
return world.getTileEntity(pos) == this && player.getDistanceSqToCenter(pos) < 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(EntityPlayer player) {
|
||||
public void openInventory(EntityPlayer player){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(EntityPlayer player) {
|
||||
public void closeInventory(EntityPlayer player){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotNumber, ItemStack itemstack) {
|
||||
public boolean isItemValidForSlot(int slotNumber, ItemStack itemstack){
|
||||
|
||||
if(itemstack == null) return true;
|
||||
if(itemstack == ItemStack.EMPTY) return true;
|
||||
|
||||
if(slotNumber >= 0 && slotNumber < ContainerArcaneWorkbench.CRYSTAL_SLOT){
|
||||
return itemstack.getItem() == WizardryItems.spell_book;
|
||||
@@ -163,8 +165,7 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory,
|
||||
return itemstack.getItem() == WizardryItems.magic_crystal;
|
||||
|
||||
}else if(slotNumber == ContainerArcaneWorkbench.WAND_SLOT){
|
||||
return itemstack != null && (itemstack.getItem() instanceof ItemWand
|
||||
|| itemstack.getItem() instanceof ItemWizardArmour
|
||||
return (itemstack.getItem() instanceof ItemWand || itemstack.getItem() instanceof ItemWizardArmour
|
||||
|| itemstack.getItem() == WizardryItems.blank_scroll);
|
||||
|
||||
}else if(slotNumber == ContainerArcaneWorkbench.UPGRADE_SLOT){
|
||||
@@ -177,49 +178,50 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory,
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound){
|
||||
|
||||
|
||||
super.readFromNBT(tagCompound);
|
||||
|
||||
NBTTagList tagList = tagCompound.getTagList("Inventory", NBT.TAG_COMPOUND);
|
||||
for(int i = 0; i < tagList.tagCount(); i++) {
|
||||
NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i);
|
||||
for(int i = 0; i < tagList.tagCount(); i++){
|
||||
NBTTagCompound tag = (NBTTagCompound)tagList.getCompoundTagAt(i);
|
||||
byte slot = tag.getByte("Slot");
|
||||
if (slot >= 0 && slot < inv.length) {
|
||||
inv[slot] = ItemStack.loadItemStackFromNBT(tag);
|
||||
if(slot >= 0 && slot < getSizeInventory()){
|
||||
setInventorySlotContents(slot, new ItemStack(tag));
|
||||
}
|
||||
}
|
||||
|
||||
// timer = tagCompound.getFloat("timer");
|
||||
// yTimer = tagCompound.getInteger("yTimer");
|
||||
// yOffset = tagCompound.getInteger("yOffset");
|
||||
// timer = tagCompound.getFloat("timer");
|
||||
// yTimer = tagCompound.getInteger("yTimer");
|
||||
// yOffset = tagCompound.getInteger("yOffset");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound){
|
||||
|
||||
super.writeToNBT(tagCompound);
|
||||
|
||||
NBTTagList itemList = new NBTTagList();
|
||||
for (int i = 0; i < inv.length; i++) {
|
||||
ItemStack stack = inv[i];
|
||||
if (stack != null) {
|
||||
for(int i = 0; i < getSizeInventory(); i++){
|
||||
ItemStack stack = getStackInSlot(i);
|
||||
if(!stack.isEmpty()){
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setByte("Slot", (byte) i);
|
||||
tag.setByte("Slot", (byte)i);
|
||||
stack.writeToNBT(tag);
|
||||
itemList.appendTag(tag);
|
||||
}
|
||||
}
|
||||
|
||||
tagCompound.setTag("Inventory", itemList);
|
||||
// tagCompound.setFloat("timer", timer);
|
||||
// tagCompound.setInteger("yTimer", yTimer);
|
||||
// tagCompound.setInteger("yOffset", yOffset);
|
||||
// tagCompound.setFloat("timer", timer);
|
||||
// tagCompound.setInteger("yTimer", yTimer);
|
||||
// tagCompound.setInteger("yOffset", yOffset);
|
||||
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final NBTTagCompound getUpdateTag(){
|
||||
return this.writeToNBT(new NBTTagCompound());
|
||||
@@ -231,24 +233,19 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
|
||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){
|
||||
readFromNBT(pkt.getNbtCompound());
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AxisAlignedBB getRenderBoundingBox()
|
||||
{
|
||||
public AxisAlignedBB getRenderBoundingBox(){
|
||||
AxisAlignedBB bb = INFINITE_EXTENT_AABB;
|
||||
Block type = getBlockType();
|
||||
if (type == WizardryBlocks.arcane_workbench)
|
||||
{
|
||||
if(type == WizardryBlocks.arcane_workbench){
|
||||
bb = new AxisAlignedBB(pos, pos.add(1, 1, 1));
|
||||
}
|
||||
else if (type != null)
|
||||
{
|
||||
AxisAlignedBB cbb = this.getWorld().getBlockState(pos).getBoundingBox(worldObj, pos);
|
||||
if (cbb != null)
|
||||
{
|
||||
}else if(type != null){
|
||||
AxisAlignedBB cbb = this.getWorld().getBlockState(pos).getBoundingBox(world, pos);
|
||||
if(cbb != null){
|
||||
bb = cbb;
|
||||
}
|
||||
}
|
||||
@@ -258,25 +255,35 @@ public class TileEntityArcaneWorkbench extends TileEntity implements IInventory,
|
||||
// What are all these for?
|
||||
|
||||
@Override
|
||||
public int getField(int id) {
|
||||
public int getField(int id){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField(int id, int value) {
|
||||
public void setField(int id, int value){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount() {
|
||||
public int getFieldCount(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
for(int i=0; i<this.inv.length; i++){
|
||||
this.inv[i] = null;
|
||||
public void clear(){
|
||||
for(int i = 0; i < getSizeInventory(); i++){
|
||||
setInventorySlotContents(i, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty(){
|
||||
for(int i = 0; i < getSizeInventory(); i++){
|
||||
if(!getStackInSlot(i).isEmpty()){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@ package electroblob.wizardry.tileentity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class TileEntityMagicLight extends TileEntityTimer {
|
||||
|
||||
|
||||
public int[] randomiser;
|
||||
public int[] randomiser2;
|
||||
|
||||
|
||||
public TileEntityMagicLight(){
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public TileEntityMagicLight(int maxTimer){
|
||||
super(maxTimer);
|
||||
randomiser = new int[30];
|
||||
@@ -18,36 +18,36 @@ public class TileEntityMagicLight extends TileEntityTimer {
|
||||
randomiser2 = new int[30];
|
||||
randomiser2[0] = -1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
|
||||
|
||||
if(randomiser.length > 0 && randomiser[0] == -1){
|
||||
for(int i=0; i<randomiser.length; i++){
|
||||
randomiser[i] = this.worldObj.rand.nextInt(10);
|
||||
for(int i = 0; i < randomiser.length; i++){
|
||||
randomiser[i] = this.world.rand.nextInt(10);
|
||||
}
|
||||
}
|
||||
if(randomiser2.length > 0 && randomiser2[0] == -1){
|
||||
for(int i=0; i<randomiser2.length; i++){
|
||||
randomiser2[i] = this.worldObj.rand.nextInt(10);
|
||||
for(int i = 0; i < randomiser2.length; i++){
|
||||
randomiser2[i] = this.world.rand.nextInt(10);
|
||||
}
|
||||
}
|
||||
super.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound) {
|
||||
super.readFromNBT(tagCompound);
|
||||
randomiser = tagCompound.getIntArray("randomiser");
|
||||
randomiser2 = tagCompound.getIntArray("randomiser2");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
|
||||
super.writeToNBT(tagCompound);
|
||||
tagCompound.setIntArray("randomiser", randomiser);
|
||||
tagCompound.setIntArray("randomiser2", randomiser2);
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound){
|
||||
super.readFromNBT(tagCompound);
|
||||
randomiser = tagCompound.getIntArray("randomiser");
|
||||
randomiser2 = tagCompound.getIntArray("randomiser2");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound){
|
||||
super.writeToNBT(tagCompound);
|
||||
tagCompound.setIntArray("randomiser", randomiser);
|
||||
tagCompound.setIntArray("randomiser2", randomiser2);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,57 +14,59 @@ public class TileEntityPlayerSave extends TileEntity implements ITickable {
|
||||
|
||||
/** The entity that created this construct */
|
||||
private WeakReference<EntityLivingBase> caster;
|
||||
|
||||
/** The UUID of the caster. Note that this is only for loading purposes; during normal updates
|
||||
* the actual entity instance is stored (so that getEntityByUUID is not called constantly),
|
||||
* so this will not always be synced (this is why it is private). */
|
||||
|
||||
/**
|
||||
* The UUID of the caster. Note that this is only for loading purposes; during normal updates the actual entity
|
||||
* instance is stored (so that getEntityByUUID is not called constantly), so this will not always be synced (this is
|
||||
* why it is private).
|
||||
*/
|
||||
private UUID casterUUID;
|
||||
|
||||
|
||||
public TileEntityPlayerSave(EntityLivingBase caster){
|
||||
this.caster = new WeakReference<EntityLivingBase>(caster);
|
||||
}
|
||||
|
||||
|
||||
public TileEntityPlayerSave(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
if(this.getCaster() == null && this.casterUUID != null){
|
||||
Entity entity = WizardryUtilities.getEntityByUUID(worldObj, casterUUID);
|
||||
Entity entity = WizardryUtilities.getEntityByUUID(world, casterUUID);
|
||||
if(entity instanceof EntityLivingBase){
|
||||
this.caster = new WeakReference<EntityLivingBase>((EntityLivingBase)entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound) {
|
||||
super.readFromNBT(tagCompound);
|
||||
casterUUID = tagCompound.getUniqueId("casterUUID");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
|
||||
|
||||
super.writeToNBT(tagCompound);
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound){
|
||||
super.readFromNBT(tagCompound);
|
||||
casterUUID = tagCompound.getUniqueId("casterUUID");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound){
|
||||
|
||||
super.writeToNBT(tagCompound);
|
||||
|
||||
if(this.getCaster() != null){
|
||||
tagCompound.setUniqueId("casterUUID", this.getCaster().getUniqueID());
|
||||
}
|
||||
|
||||
tagCompound.setUniqueId("casterUUID", this.getCaster().getUniqueID());
|
||||
}
|
||||
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the EntityLivingBase that created this construct, or null if it no longer exists. Cases where the
|
||||
* entity may no longer exist are: entity died or was deleted, mob despawned, player logged out, entity teleported
|
||||
* to another dimension, or this construct simply had no caster in the first place.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the EntityLivingBase that created this construct, or null if it no longer exists. Cases where the entity
|
||||
* may no longer exist are: entity died or was deleted, mob despawned, player logged out, entity teleported to
|
||||
* another dimension, or this construct simply had no caster in the first place.
|
||||
*/
|
||||
public EntityLivingBase getCaster() {
|
||||
public EntityLivingBase getCaster(){
|
||||
return caster == null ? null : caster.get();
|
||||
}
|
||||
|
||||
|
||||
public void setCaster(EntityLivingBase caster){
|
||||
this.caster = new WeakReference<EntityLivingBase>(caster);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -22,152 +23,158 @@ public class TileEntityStatue extends TileEntity implements ITickable {
|
||||
public boolean isIce;
|
||||
private int timer;
|
||||
private int lifetime = 600;
|
||||
/** <b>[Client-side]</b> Keeps track of the destroy stage for the block associated with this tile entity
|
||||
* for rendering purposes. Will be 0 if position is not 1. */
|
||||
/**
|
||||
* <b>[Client-side]</b> Keeps track of the destroy stage for the block associated with this tile entity for
|
||||
* rendering purposes. Will be 0 if position is not 1.
|
||||
*/
|
||||
public int destroyStage;
|
||||
|
||||
|
||||
public TileEntityStatue(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public TileEntityStatue(boolean isIce){
|
||||
this.isIce = isIce;
|
||||
this.timer = 0;
|
||||
}
|
||||
|
||||
/** The number of stone blocks that this petrified creature is made of.*/
|
||||
|
||||
/** The number of stone blocks that this petrified creature is made of. */
|
||||
public int parts;
|
||||
|
||||
/** The position within the petrified creature this particular tileentity holds.
|
||||
* 1 is at the bottom.*/
|
||||
|
||||
/**
|
||||
* The position within the petrified creature this particular tileentity holds. 1 is at the bottom.
|
||||
*/
|
||||
public int position = 1;
|
||||
|
||||
|
||||
public void setCreatureAndPart(EntityLiving entity, int position, int parts){
|
||||
this.creature = entity;
|
||||
this.position = position;
|
||||
this.parts = parts;
|
||||
// Aligns the entity with the block so the render bounding box works correctly, and also for visual effect when
|
||||
// broken out.
|
||||
if(position == 1) creature.setPosition(this.getPos().getX() + 0.5, this.getPos().getY(), this.getPos().getZ() + 0.5);
|
||||
if(position == 1)
|
||||
creature.setPosition(this.getPos().getX() + 0.5, this.getPos().getY(), this.getPos().getZ() + 0.5);
|
||||
}
|
||||
|
||||
|
||||
public void setLifetime(int lifetime){
|
||||
this.lifetime = lifetime;
|
||||
}
|
||||
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public AxisAlignedBB getRenderBoundingBox(){
|
||||
|
||||
AxisAlignedBB bb = INFINITE_EXTENT_AABB;
|
||||
Block type = getBlockType();
|
||||
// Allows the renderer to render the entity even when the bottom block is not visible.
|
||||
// Was only done for position 1, now done for all positions so the breaking animation works properly.
|
||||
if(this.creature != null){
|
||||
// Now uses the entity's bounding box
|
||||
bb = this.creature.getRenderBoundingBox();
|
||||
//bb = new AxisAlignedBB(xCoord, yCoord, zCoord, xCoord + 1, yCoord + this.parts, zCoord + 1);
|
||||
|
||||
}else if(type != null){
|
||||
|
||||
AxisAlignedBB cbb = this.getWorld().getBlockState(pos).getBoundingBox(worldObj, pos);
|
||||
if (cbb != null)
|
||||
{
|
||||
bb = cbb;
|
||||
}
|
||||
}
|
||||
return bb;
|
||||
}
|
||||
|
||||
public AxisAlignedBB getRenderBoundingBox(){
|
||||
|
||||
AxisAlignedBB bb = INFINITE_EXTENT_AABB;
|
||||
Block type = getBlockType();
|
||||
// Allows the renderer to render the entity even when the bottom block is not visible.
|
||||
// Was only done for position 1, now done for all positions so the breaking animation works properly.
|
||||
if(this.creature != null){
|
||||
// Now uses the entity's bounding box
|
||||
bb = this.creature.getRenderBoundingBox();
|
||||
// bb = new AxisAlignedBB(xCoord, yCoord, zCoord, xCoord + 1, yCoord + this.parts, zCoord + 1);
|
||||
|
||||
}else if(type != null){
|
||||
|
||||
AxisAlignedBB cbb = this.getWorld().getBlockState(pos).getBoundingBox(world, pos);
|
||||
if(cbb != null){
|
||||
bb = cbb;
|
||||
}
|
||||
}
|
||||
return bb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRenderBreaking(){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
|
||||
|
||||
this.timer++;
|
||||
|
||||
//System.out.println(entityName);
|
||||
|
||||
// System.out.println(entityName);
|
||||
if(this.creature == null && entityName != null){
|
||||
this.creature = (EntityLiving) EntityList.createEntityByName(this.entityName, this.worldObj);
|
||||
this.creature = (EntityLiving)EntityList.createEntityByIDFromName(new ResourceLocation(this.entityName),
|
||||
this.world);
|
||||
if(this.creature != null){
|
||||
this.creature.readFromNBT(entityCompound);
|
||||
this.creature.rotationYawHead = this.entityYawHead;
|
||||
this.creature.renderYawOffset = this.entityYawOffset;
|
||||
}
|
||||
}
|
||||
|
||||
//System.out.println("Coords: " + this.xCoord + ", " + this.yCoord + ", " + this.zCoord);
|
||||
|
||||
// System.out.println("Coords: " + this.xCoord + ", " + this.yCoord + ", " + this.zCoord);
|
||||
// Breaks the block at light levels of 7 or below, with a higher chance the lower the light level.
|
||||
// The chance is (8 - light level)/12, so at light 0 the chance is 3/4 and at light 7 the chance is 1/12.
|
||||
if(!this.worldObj.isRemote && this.timer % 200 == 0 && this.timer > lifetime && !this.isIce && this.position == 1){
|
||||
if(!this.world.isRemote && this.timer % 200 == 0 && this.timer > lifetime && !this.isIce && this.position == 1){
|
||||
// TESTME: There are about 10 different light-related methods in world now... is this the right one?
|
||||
if(this.worldObj.getLight(pos) < this.worldObj.rand.nextInt(12) - 3){
|
||||
// This is all that is needed because destroyBlock invokes the breakBlock function in BlockPetrifiedStone
|
||||
if(this.world.getLight(pos) < this.world.rand.nextInt(12) - 3){
|
||||
// This is all that is needed because destroyBlock invokes the breakBlock function in
|
||||
// BlockPetrifiedStone
|
||||
// and that function handles all the spawning and stuff.
|
||||
this.worldObj.destroyBlock(pos, false);
|
||||
this.world.destroyBlock(pos, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Breaks the block after 30 secs
|
||||
if(!this.worldObj.isRemote && this.timer > lifetime && this.isIce){
|
||||
if(!this.world.isRemote && this.timer > lifetime && this.isIce){
|
||||
if(this.position == 1){
|
||||
// This is all that is needed because destroyBlock invokes the breakBlock function in BlockPetrifiedStone
|
||||
// This is all that is needed because destroyBlock invokes the breakBlock function in
|
||||
// BlockPetrifiedStone
|
||||
// and that function handles all the spawning and stuff.
|
||||
this.worldObj.destroyBlock(pos, false);
|
||||
this.world.destroyBlock(pos, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound) {
|
||||
super.readFromNBT(tagCompound);
|
||||
position = tagCompound.getInteger("position");
|
||||
parts = tagCompound.getInteger("parts");
|
||||
entityCompound = tagCompound.getCompoundTag("entity");
|
||||
entityName = tagCompound.getString("entityName");
|
||||
timer = tagCompound.getInteger("timer");
|
||||
lifetime = tagCompound.getInteger("lifetime");
|
||||
isIce = tagCompound.getBoolean("isIce");
|
||||
entityYawHead = tagCompound.getFloat("entityYawHead");
|
||||
entityYawOffset = tagCompound.getFloat("entityYawOffset");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
|
||||
super.writeToNBT(tagCompound);
|
||||
tagCompound.setInteger("position", position);
|
||||
tagCompound.setInteger("parts", parts);
|
||||
entityCompound = new NBTTagCompound();
|
||||
if(creature != null){
|
||||
creature.writeToNBT(entityCompound);
|
||||
tagCompound.setString("entityName", EntityList.getEntityString(creature));
|
||||
tagCompound.setFloat("entityYawHead", creature.rotationYawHead);
|
||||
tagCompound.setFloat("entityYawOffset", creature.renderYawOffset);
|
||||
}
|
||||
tagCompound.setTag("entity", entityCompound);
|
||||
tagCompound.setInteger("timer", timer);
|
||||
tagCompound.setInteger("lifetime", lifetime);
|
||||
tagCompound.setBoolean("isIce", isIce);
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound){
|
||||
super.readFromNBT(tagCompound);
|
||||
position = tagCompound.getInteger("position");
|
||||
parts = tagCompound.getInteger("parts");
|
||||
entityCompound = tagCompound.getCompoundTag("entity");
|
||||
entityName = tagCompound.getString("entityName");
|
||||
timer = tagCompound.getInteger("timer");
|
||||
lifetime = tagCompound.getInteger("lifetime");
|
||||
isIce = tagCompound.getBoolean("isIce");
|
||||
entityYawHead = tagCompound.getFloat("entityYawHead");
|
||||
entityYawOffset = tagCompound.getFloat("entityYawOffset");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound){
|
||||
super.writeToNBT(tagCompound);
|
||||
tagCompound.setInteger("position", position);
|
||||
tagCompound.setInteger("parts", parts);
|
||||
entityCompound = new NBTTagCompound();
|
||||
if(creature != null){
|
||||
creature.writeToNBT(entityCompound);
|
||||
tagCompound.setString("entityName", EntityList.getEntityString(creature));
|
||||
tagCompound.setFloat("entityYawHead", creature.rotationYawHead);
|
||||
tagCompound.setFloat("entityYawOffset", creature.renderYawOffset);
|
||||
}
|
||||
tagCompound.setTag("entity", entityCompound);
|
||||
tagCompound.setInteger("timer", timer);
|
||||
tagCompound.setInteger("lifetime", lifetime);
|
||||
tagCompound.setBoolean("isIce", isIce);
|
||||
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
}
|
||||
|
||||
@Override
|
||||
public final NBTTagCompound getUpdateTag(){
|
||||
return this.writeToNBT(new NBTTagCompound());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
public SPacketUpdateTileEntity getUpdatePacket(){
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeToNBT(tag);
|
||||
return new SPacketUpdateTileEntity(pos, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){
|
||||
NBTTagCompound tag = pkt.getNbtCompound();
|
||||
readFromNBT(tag);
|
||||
}
|
||||
|
||||
@@ -8,69 +8,70 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ITickable;
|
||||
|
||||
public class TileEntityTimer extends TileEntity implements ITickable {
|
||||
|
||||
|
||||
public int timer = 0;
|
||||
public int maxTimer;
|
||||
|
||||
|
||||
public TileEntityTimer(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public TileEntityTimer(int maxTimer){
|
||||
this.maxTimer = maxTimer;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
timer++;
|
||||
if(!this.worldObj.isRemote){
|
||||
//System.out.println("Timer: " + timer + "/" + maxTimer);
|
||||
if(!this.world.isRemote){
|
||||
// System.out.println("Timer: " + timer + "/" + maxTimer);
|
||||
}
|
||||
if(timer > maxTimer && !this.worldObj.isRemote){// && this.worldObj.getBlockId(xCoord, yCoord, zCoord) == Wizardry.magicLight.blockID){
|
||||
if(timer > maxTimer && !this.world.isRemote){// && this.world.getBlockId(xCoord, yCoord, zCoord) ==
|
||||
// Wizardry.magicLight.blockID){
|
||||
if(this.getBlockType() instanceof BlockVanishingCobweb){
|
||||
// destroyBlock breaks the block as if broken by a player, with sound and particles.
|
||||
this.worldObj.destroyBlock(pos, false);
|
||||
this.world.destroyBlock(pos, false);
|
||||
}else{
|
||||
this.worldObj.setBlockToAir(pos);
|
||||
this.world.setBlockToAir(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setLifetime(int lifetime){
|
||||
this.maxTimer = lifetime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound) {
|
||||
super.readFromNBT(tagCompound);
|
||||
timer = tagCompound.getInteger("timer");
|
||||
maxTimer = tagCompound.getInteger("maxTimer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
|
||||
super.writeToNBT(tagCompound);
|
||||
tagCompound.setInteger("timer", timer);
|
||||
tagCompound.setInteger("maxTimer", maxTimer);
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagCompound){
|
||||
super.readFromNBT(tagCompound);
|
||||
timer = tagCompound.getInteger("timer");
|
||||
maxTimer = tagCompound.getInteger("maxTimer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound){
|
||||
super.writeToNBT(tagCompound);
|
||||
tagCompound.setInteger("timer", timer);
|
||||
tagCompound.setInteger("maxTimer", maxTimer);
|
||||
return tagCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
}
|
||||
|
||||
@Override
|
||||
public final NBTTagCompound getUpdateTag(){
|
||||
return this.writeToNBT(new NBTTagCompound());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SPacketUpdateTileEntity getUpdatePacket() {
|
||||
|
||||
@Override
|
||||
public SPacketUpdateTileEntity getUpdatePacket(){
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeToNBT(tag);
|
||||
return new SPacketUpdateTileEntity(pos, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
|
||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){
|
||||
NBTTagCompound tag = pkt.getNbtCompound();
|
||||
readFromNBT(tag);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user