Improved satellite loot system again so lunar loot is in lunar satellite and not in random class

This commit is contained in:
Toshayo 2023-06-22 09:01:09 +02:00
parent 9f873e6b76
commit 0be6b66446
No known key found for this signature in database
GPG Key ID: 7DC46644B561B1B4
5 changed files with 358 additions and 405 deletions

View File

@ -10,11 +10,8 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World; import net.minecraft.world.World;
public class EntityMinerRocket extends Entity { public class EntityMinerRocket extends Entity {
//0 landing, 1 unloading, 2 lifting //0 landing, 1 unloading, 2 lifting
public int timer = 0; public int timer = 0;
//0 asteroid, 1 moon
public String satelliteClassName = "com.hbm.saveddata.satellites.SatelliteMiner";
public EntityMinerRocket(World p_i1582_1_) { public EntityMinerRocket(World p_i1582_1_) {
super(p_i1582_1_); super(p_i1582_1_);
@ -24,13 +21,12 @@ public class EntityMinerRocket extends Entity {
@Override @Override
protected void entityInit() { protected void entityInit() {
this.dataWatcher.addObject(16, Integer.valueOf(0)); this.dataWatcher.addObject(16, 0);
this.dataWatcher.addObject(17, Integer.valueOf(0)); this.dataWatcher.addObject(17, 0);
} }
@Override @Override
public void onUpdate() { public void onUpdate() {
if(dataWatcher.getWatchableObjectInt(16) == 0) if(dataWatcher.getWatchableObjectInt(16) == 0)
motionY = -0.75; motionY = -0.75;
if(dataWatcher.getWatchableObjectInt(16) == 1) if(dataWatcher.getWatchableObjectInt(16) == 1)
@ -43,7 +39,6 @@ public class EntityMinerRocket extends Entity {
this.setPositionAndRotation(posX + motionX, posY + motionY, posZ + motionZ, 0.0F, 0.0F); this.setPositionAndRotation(posX + motionX, posY + motionY, posZ + motionZ, 0.0F, 0.0F);
if(dataWatcher.getWatchableObjectInt(16) == 0 && worldObj.getBlock((int)(posX - 0.5), (int)(posY - 0.5), (int)(posZ - 0.5)) == ModBlocks.sat_dock) { if(dataWatcher.getWatchableObjectInt(16) == 0 && worldObj.getBlock((int)(posX - 0.5), (int)(posY - 0.5), (int)(posZ - 0.5)) == ModBlocks.sat_dock) {
dataWatcher.updateObject(16, 1); dataWatcher.updateObject(16, 1);
motionY = 0; motionY = 0;
@ -55,7 +50,6 @@ public class EntityMinerRocket extends Entity {
} }
if(dataWatcher.getWatchableObjectInt(16) == 1) { if(dataWatcher.getWatchableObjectInt(16) == 1) {
if(!worldObj.isRemote && ticksExisted % 4 == 0) if(!worldObj.isRemote && ticksExisted % 4 == 0)
ExplosionLarge.spawnShock(worldObj, posX, posY, posZ, 1 + rand.nextInt(3), 1 + rand.nextGaussian()); ExplosionLarge.spawnShock(worldObj, posX, posY, posZ, 1 + rand.nextInt(3), 1 + rand.nextGaussian());
@ -79,7 +73,6 @@ public class EntityMinerRocket extends Entity {
dataWatcher.updateObject(16, nbt.getInteger("mode")); dataWatcher.updateObject(16, nbt.getInteger("mode"));
dataWatcher.updateObject(17, nbt.getInteger("sat")); dataWatcher.updateObject(17, nbt.getInteger("sat"));
timer = nbt.getInteger("timer"); timer = nbt.getInteger("timer");
satelliteClassName = nbt.getString("type");
} }
@Override @Override
@ -87,7 +80,5 @@ public class EntityMinerRocket extends Entity {
nbt.setInteger("mode", dataWatcher.getWatchableObjectInt(16)); nbt.setInteger("mode", dataWatcher.getWatchableObjectInt(16));
nbt.setInteger("sat", dataWatcher.getWatchableObjectInt(17)); nbt.setInteger("sat", dataWatcher.getWatchableObjectInt(17));
nbt.setInteger("timer", timer); nbt.setInteger("timer", timer);
nbt.setString("type", satelliteClassName);
} }
} }

View File

@ -1,3 +1,20 @@
package com.hbm.saveddata.satellites; package com.hbm.saveddata.satellites;
public class SatelliteLunarMiner extends SatelliteMiner { } import com.hbm.blocks.ModBlocks;
import com.hbm.items.ModItems;
import com.hbm.util.WeightedRandomObject;
import net.minecraft.item.ItemStack;
public class SatelliteLunarMiner extends SatelliteMiner {
static {
registerCargo(new WeightedRandomObject[] {
new WeightedRandomObject(new ItemStack(ModBlocks.moon_turf, 48), 5),
new WeightedRandomObject(new ItemStack(ModBlocks.moon_turf, 32), 7),
new WeightedRandomObject(new ItemStack(ModBlocks.moon_turf, 16), 5),
new WeightedRandomObject(new ItemStack(ModItems.powder_lithium, 3), 5),
new WeightedRandomObject(new ItemStack(ModItems.powder_iron, 3), 5),
new WeightedRandomObject(new ItemStack(ModItems.crystal_iron, 1), 1),
new WeightedRandomObject(new ItemStack(ModItems.crystal_lithium, 1), 1)
});
}
}

View File

@ -1,8 +1,45 @@
package com.hbm.saveddata.satellites; package com.hbm.saveddata.satellites;
import com.hbm.blocks.ModBlocks;
import com.hbm.items.ModItems;
import com.hbm.util.WeightedRandomObject;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
public class SatelliteMiner extends Satellite { public class SatelliteMiner extends Satellite {
/**
* {@link WeightedRandomObject} array with loot the satellite will deliver.
*/
private static WeightedRandomObject[] CARGO = new WeightedRandomObject[] {
new WeightedRandomObject(new ItemStack(ModItems.powder_aluminium, 3), 10),
new WeightedRandomObject(new ItemStack(ModItems.powder_iron, 3), 10),
new WeightedRandomObject(new ItemStack(ModItems.powder_titanium, 2), 8),
new WeightedRandomObject(new ItemStack(ModItems.crystal_tungsten, 2), 7),
new WeightedRandomObject(new ItemStack(ModItems.powder_coal, 4), 15),
new WeightedRandomObject(new ItemStack(ModItems.powder_uranium, 2), 5),
new WeightedRandomObject(new ItemStack(ModItems.powder_plutonium, 1), 5),
new WeightedRandomObject(new ItemStack(ModItems.powder_thorium, 2), 7),
new WeightedRandomObject(new ItemStack(ModItems.powder_desh_mix, 3), 5),
new WeightedRandomObject(new ItemStack(ModItems.powder_diamond, 2), 7),
new WeightedRandomObject(new ItemStack(Items.redstone, 5), 15),
new WeightedRandomObject(new ItemStack(ModItems.powder_nitan_mix, 2), 5),
new WeightedRandomObject(new ItemStack(ModItems.powder_power, 2), 5),
new WeightedRandomObject(new ItemStack(ModItems.powder_copper, 5), 15),
new WeightedRandomObject(new ItemStack(ModItems.powder_lead, 3), 10),
new WeightedRandomObject(new ItemStack(ModItems.fluorite, 4), 15),
new WeightedRandomObject(new ItemStack(ModItems.powder_lapis, 4), 10),
new WeightedRandomObject(new ItemStack(ModItems.powder_combine_steel, 1), 1),
new WeightedRandomObject(new ItemStack(ModItems.crystal_aluminium, 1), 5),
new WeightedRandomObject(new ItemStack(ModItems.crystal_gold, 1), 5),
new WeightedRandomObject(new ItemStack(ModItems.crystal_phosphorus, 1), 10),
new WeightedRandomObject(new ItemStack(ModBlocks.gravel_diamond, 1), 3),
new WeightedRandomObject(new ItemStack(ModItems.crystal_uranium, 1), 3),
new WeightedRandomObject(new ItemStack(ModItems.crystal_plutonium, 1), 3),
new WeightedRandomObject(new ItemStack(ModItems.crystal_trixite, 1), 1),
new WeightedRandomObject(new ItemStack(ModItems.crystal_starmetal, 1), 1),
new WeightedRandomObject(new ItemStack(ModItems.crystal_lithium, 2), 4)
};
public long lastOp; public long lastOp;
@ -17,4 +54,20 @@ public class SatelliteMiner extends Satellite {
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
lastOp = nbt.getLong("lastOp"); lastOp = nbt.getLong("lastOp");
} }
/**
* Replaces cargo of the satellite.
* @param cargo - Array of {@link WeightedRandomObject} representing the loot that will be delivered.
*/
public static void registerCargo(WeightedRandomObject[] cargo) {
CARGO = cargo;
}
/**
* Gets items the satellite can deliver.
* @return - Array of {@link WeightedRandomObject} of satellite loot.
*/
public WeightedRandomObject[] getCargo() {
return CARGO;
}
} }

View File

@ -1,82 +0,0 @@
package com.hbm.saveddata.satellites;
import com.hbm.blocks.ModBlocks;
import com.hbm.items.ModItems;
import com.hbm.util.WeightedRandomObject;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import java.util.HashMap;
public class SatelliteMinerCargoRegistry {
private static final HashMap<String, WeightedRandomObject[]> cargo = new HashMap<String, WeightedRandomObject[]>() {{
put(SatelliteMiner.class.getName(), new WeightedRandomObject[] {
new WeightedRandomObject(new ItemStack(ModItems.powder_aluminium, 3), 10),
new WeightedRandomObject(new ItemStack(ModItems.powder_iron, 3), 10),
new WeightedRandomObject(new ItemStack(ModItems.powder_titanium, 2), 8),
new WeightedRandomObject(new ItemStack(ModItems.crystal_tungsten, 2), 7),
new WeightedRandomObject(new ItemStack(ModItems.powder_coal, 4), 15),
new WeightedRandomObject(new ItemStack(ModItems.powder_uranium, 2), 5),
new WeightedRandomObject(new ItemStack(ModItems.powder_plutonium, 1), 5),
new WeightedRandomObject(new ItemStack(ModItems.powder_thorium, 2), 7),
new WeightedRandomObject(new ItemStack(ModItems.powder_desh_mix, 3), 5),
new WeightedRandomObject(new ItemStack(ModItems.powder_diamond, 2), 7),
new WeightedRandomObject(new ItemStack(Items.redstone, 5), 15),
new WeightedRandomObject(new ItemStack(ModItems.powder_nitan_mix, 2), 5),
new WeightedRandomObject(new ItemStack(ModItems.powder_power, 2), 5),
new WeightedRandomObject(new ItemStack(ModItems.powder_copper, 5), 15),
new WeightedRandomObject(new ItemStack(ModItems.powder_lead, 3), 10),
new WeightedRandomObject(new ItemStack(ModItems.fluorite, 4), 15),
new WeightedRandomObject(new ItemStack(ModItems.powder_lapis, 4), 10),
new WeightedRandomObject(new ItemStack(ModItems.powder_combine_steel, 1), 1),
new WeightedRandomObject(new ItemStack(ModItems.crystal_aluminium, 1), 5),
new WeightedRandomObject(new ItemStack(ModItems.crystal_gold, 1), 5),
new WeightedRandomObject(new ItemStack(ModItems.crystal_phosphorus, 1), 10),
new WeightedRandomObject(new ItemStack(ModBlocks.gravel_diamond, 1), 3),
new WeightedRandomObject(new ItemStack(ModItems.crystal_uranium, 1), 3),
new WeightedRandomObject(new ItemStack(ModItems.crystal_plutonium, 1), 3),
new WeightedRandomObject(new ItemStack(ModItems.crystal_trixite, 1), 1),
new WeightedRandomObject(new ItemStack(ModItems.crystal_starmetal, 1), 1),
new WeightedRandomObject(new ItemStack(ModItems.crystal_lithium, 2), 4)
});
put(SatelliteLunarMiner.class.getName(), new WeightedRandomObject[] {
new WeightedRandomObject(new ItemStack(ModBlocks.moon_turf, 48), 5),
new WeightedRandomObject(new ItemStack(ModBlocks.moon_turf, 32), 7),
new WeightedRandomObject(new ItemStack(ModBlocks.moon_turf, 16), 5),
new WeightedRandomObject(new ItemStack(ModItems.powder_lithium, 3), 5),
new WeightedRandomObject(new ItemStack(ModItems.powder_iron, 3), 5),
new WeightedRandomObject(new ItemStack(ModItems.crystal_iron, 1), 1),
new WeightedRandomObject(new ItemStack(ModItems.crystal_lithium, 1), 1),
});
}};
/**
* Register cargo for specified satellite object
* @param o - Satellite object
* @param cargo - WeightedRandomObject array with loot
*/
public static void register(Object o, WeightedRandomObject[] cargo) {
SatelliteMinerCargoRegistry.cargo.put(o.getClass().getName(), cargo);
}
/**
* Register cargo for specified satellite class
* @param c - Satellite class
* @param cargo - WeightedRandomObject array with loot
*/
public static void register(Class<?> c, WeightedRandomObject[] cargo) {
SatelliteMinerCargoRegistry.cargo.put(c.getName(), cargo);
}
/**
* Get loot by satellite class name
* @param satelliteName - Satellite class name, like com.hbm.saveddata.satellites.SatelliteMiner
* @return - WeightedRandomObject array with loot
*/
public static WeightedRandomObject[] getCargo(String satelliteName) {
if(cargo.containsKey(satelliteName)) {
return cargo.get(satelliteName);
}
return new WeightedRandomObject[0];
}
}

View File

@ -1,8 +1,5 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.List;
import java.util.Random;
import com.hbm.entity.missile.EntityMinerRocket; import com.hbm.entity.missile.EntityMinerRocket;
import com.hbm.explosion.ExplosionNukeSmall; import com.hbm.explosion.ExplosionNukeSmall;
import com.hbm.inventory.container.ContainerSatDock; import com.hbm.inventory.container.ContainerSatDock;
@ -11,10 +8,8 @@ import com.hbm.items.ISatChip;
import com.hbm.saveddata.SatelliteSavedData; import com.hbm.saveddata.SatelliteSavedData;
import com.hbm.saveddata.satellites.Satellite; import com.hbm.saveddata.satellites.Satellite;
import com.hbm.saveddata.satellites.SatelliteMiner; import com.hbm.saveddata.satellites.SatelliteMiner;
import com.hbm.saveddata.satellites.SatelliteMinerCargoRegistry;
import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.IGUIProvider;
import com.hbm.util.WeightedRandomObject; import com.hbm.util.WeightedRandomObject;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
@ -31,355 +26,334 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.WeightedRandom; import net.minecraft.util.WeightedRandom;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.List;
import java.util.Random;
public class TileEntityMachineSatDock extends TileEntity implements ISidedInventory, IGUIProvider { public class TileEntityMachineSatDock extends TileEntity implements ISidedInventory, IGUIProvider {
private ItemStack[] slots;
private ItemStack[] slots; private static final int[] access = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
private static final int[] access = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; private String customName;
private String customName; public TileEntityMachineSatDock() {
slots = new ItemStack[16];
}
public TileEntityMachineSatDock() { @Override
slots = new ItemStack[16]; public int getSizeInventory() {
return slots.length;
}
@Override
public ItemStack getStackInSlot(int i) {
return slots[i];
}
@Override
public ItemStack getStackInSlotOnClosing(int i) {
if (slots[i] != null) {
ItemStack itemStack = slots[i];
slots[i] = null;
return itemStack;
} else {
return null;
}
}
@Override
public void setInventorySlotContents(int i, ItemStack itemStack) {
slots[i] = itemStack;
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
itemStack.stackSize = getInventoryStackLimit();
}
}
@Override
public String getInventoryName() {
return this.hasCustomInventoryName() ? this.customName : "container.satDock";
}
@Override
public boolean hasCustomInventoryName() {
return this.customName != null && this.customName.length() > 0;
}
public void setCustomName(String name) {
this.customName = name;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
if (worldObj.getTileEntity(xCoord, yCoord, zCoord) != this) {
return false;
} else {
return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 64;
}
}
//You scrubs aren't needed for anything (right now)
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemStack) {
return i != 2 && i != 3 && i != 4 && i != 5;
} }
@Override @Override
public int getSizeInventory() { public ItemStack decrStackSize(int i, int j) {
return slots.length; if (slots[i] != null) {
} if (slots[i].stackSize <= j) {
ItemStack itemStack = slots[i];
@Override slots[i] = null;
public ItemStack getStackInSlot(int i) { return itemStack;
return slots[i]; }
} ItemStack itemStack1 = slots[i].splitStack(j);
if (slots[i].stackSize == 0) {
@Override slots[i] = null;
public ItemStack getStackInSlotOnClosing(int i) { }
if(slots[i] != null) {
ItemStack itemStack = slots[i]; return itemStack1;
slots[i] = null; } else {
return itemStack; return null;
} else { }
return null; }
}
} @Override
public void readFromNBT(NBTTagCompound nbt) {
@Override super.readFromNBT(nbt);
public void setInventorySlotContents(int i, ItemStack itemStack) { NBTTagList list = nbt.getTagList("items", 10);
slots[i] = itemStack;
if(itemStack != null && itemStack.stackSize > getInventoryStackLimit()) { slots = new ItemStack[getSizeInventory()];
itemStack.stackSize = getInventoryStackLimit();
} for (int i = 0; i < list.tagCount(); i++) {
} NBTTagCompound nbt1 = list.getCompoundTagAt(i);
byte b0 = nbt1.getByte("slot");
@Override if (b0 >= 0 && b0 < slots.length) {
public String getInventoryName() { slots[b0] = ItemStack.loadItemStackFromNBT(nbt1);
return this.hasCustomInventoryName() ? this.customName : "container.satDock"; }
} }
}
@Override
public boolean hasCustomInventoryName() { @Override
return this.customName != null && this.customName.length() > 0; public void writeToNBT(NBTTagCompound nbt) {
} super.writeToNBT(nbt);
NBTTagList list = new NBTTagList();
public void setCustomName(String name) {
this.customName = name; for (int i = 0; i < slots.length; i++) {
} if (slots[i] != null) {
NBTTagCompound nbt1 = new NBTTagCompound();
@Override nbt1.setByte("slot", (byte) i);
public int getInventoryStackLimit() { slots[i].writeToNBT(nbt1);
return 64; list.appendTag(nbt1);
} }
}
@Override nbt.setTag("items", list);
public boolean isUseableByPlayer(EntityPlayer player) { }
if(worldObj.getTileEntity(xCoord, yCoord, zCoord) != this) {
return false; @Override
} else { public int[] getAccessibleSlotsFromSide(int p_94128_1_) {
return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 64; return access;
} }
}
@Override
//You scrubs aren't needed for anything (right now) public boolean canInsertItem(int i, ItemStack itemStack, int j) {
@Override return this.isItemValidForSlot(i, itemStack);
public void openInventory() {} }
@Override
public void closeInventory() {} @Override
public boolean canExtractItem(int i, ItemStack itemStack, int j) {
@Override return true;
public boolean isItemValidForSlot(int i, ItemStack itemStack) { }
if(i == 2 || i == 3 || i == 4 || i == 5) {
return false; SatelliteSavedData data = null;
}
@Override
return true; public void updateEntity() {
} if (!worldObj.isRemote) {
if (data == null)
@Override data = (SatelliteSavedData) worldObj.perWorldStorage.loadData(SatelliteSavedData.class, "satellites");
public ItemStack decrStackSize(int i, int j) {
if(slots[i] != null) { if (data == null) {
if(slots[i].stackSize <= j) { worldObj.perWorldStorage.setData("satellites", new SatelliteSavedData());
ItemStack itemStack = slots[i]; data = (SatelliteSavedData) worldObj.perWorldStorage.loadData(SatelliteSavedData.class, "satellites");
slots[i] = null; }
return itemStack; data.markDirty();
}
ItemStack itemStack1 = slots[i].splitStack(j); if (data != null && slots[15] != null) {
if(slots[i].stackSize == 0) { int freq = ISatChip.getFreqS(slots[15]);
slots[i] = null;
} Satellite sat = data.getSatFromFreq(freq);
return itemStack1; int delay = 10 * 60 * 1000;
} else {
return null; if (sat instanceof SatelliteMiner) {
} SatelliteMiner miner = (SatelliteMiner) sat;
}
if (miner.lastOp + delay < System.currentTimeMillis()) {
@Override EntityMinerRocket rocket = new EntityMinerRocket(worldObj);
public void readFromNBT(NBTTagCompound nbt) { rocket.posX = xCoord + 0.5;
super.readFromNBT(nbt); rocket.posY = 300;
NBTTagList list = nbt.getTagList("items", 10); rocket.posZ = zCoord + 0.5;
slots = new ItemStack[getSizeInventory()]; rocket.getDataWatcher().updateObject(17, freq);
worldObj.spawnEntityInWorld(rocket);
for(int i = 0; i < list.tagCount(); i++) { miner.lastOp = System.currentTimeMillis();
NBTTagCompound nbt1 = list.getCompoundTagAt(i); data.markDirty();
byte b0 = nbt1.getByte("slot"); }
if(b0 >= 0 && b0 < slots.length) { }
slots[b0] = ItemStack.loadItemStackFromNBT(nbt1); }
}
} List<Entity> list = worldObj.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB.getBoundingBox(xCoord - 0.25 + 0.5, yCoord + 0.75, zCoord - 0.25 + 0.5, xCoord + 0.25 + 0.5, yCoord + 2, zCoord + 0.25 + 0.5));
}
for (Entity e : list) {
@Override if (e instanceof EntityMinerRocket) {
public void writeToNBT(NBTTagCompound nbt) { EntityMinerRocket rocket = (EntityMinerRocket) e;
super.writeToNBT(nbt);
NBTTagList list = new NBTTagList(); if (slots[15] != null && ISatChip.getFreqS(slots[15]) != rocket.getDataWatcher().getWatchableObjectInt(17)) {
rocket.setDead();
for(int i = 0; i < slots.length; i++) { ExplosionNukeSmall.explode(worldObj, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, ExplosionNukeSmall.PARAMS_TOTS);
if(slots[i] != null) { break;
NBTTagCompound nbt1 = new NBTTagCompound(); }
nbt1.setByte("slot", (byte) i);
slots[i].writeToNBT(nbt1); if (rocket.getDataWatcher().getWatchableObjectInt(16) == 1 && rocket.timer == 50) {
list.appendTag(nbt1); Satellite sat = data.getSatFromFreq(ISatChip.getFreqS(slots[15]));
} unloadCargo((SatelliteMiner) sat);
} }
nbt.setTag("items", list); }
} }
@Override ejectInto(xCoord + 2, yCoord, zCoord);
public int[] getAccessibleSlotsFromSide(int p_94128_1_) { ejectInto(xCoord - 2, yCoord, zCoord);
return access; ejectInto(xCoord, yCoord, zCoord + 2);
} ejectInto(xCoord, yCoord, zCoord - 2);
}
@Override }
public boolean canInsertItem(int i, ItemStack itemStack, int j) {
return this.isItemValidForSlot(i, itemStack); static final Random rand = new Random();
}
private void unloadCargo(SatelliteMiner satellite) {
@Override int items = rand.nextInt(6) + 10;
public boolean canExtractItem(int i, ItemStack itemStack, int j) {
return true; WeightedRandomObject[] cargo = satellite.getCargo();
}
for (int i = 0; i < items; i++) {
SatelliteSavedData data = null; ItemStack stack = ((WeightedRandomObject) WeightedRandom.getRandomItem(rand, cargo)).asStack();
addToInv(stack.copy());
@Override }
public void updateEntity() { }
if(!worldObj.isRemote) { private void addToInv(ItemStack stack) {
for (int i = 0; i < 15; i++) {
if(data == null) if (slots[i] != null && slots[i].getItem() == stack.getItem() && slots[i].getItemDamage() == stack.getItemDamage() && slots[i].stackSize < slots[i].getMaxStackSize()) {
data = (SatelliteSavedData) worldObj.perWorldStorage.loadData(SatelliteSavedData.class, "satellites"); int toAdd = Math.min(slots[i].getMaxStackSize() - slots[i].stackSize, stack.stackSize);
if(data == null) { slots[i].stackSize += toAdd;
worldObj.perWorldStorage.setData("satellites", new SatelliteSavedData()); stack.stackSize -= toAdd;
data = (SatelliteSavedData) worldObj.perWorldStorage.loadData(SatelliteSavedData.class, "satellites");
} if (stack.stackSize <= 0) return;
data.markDirty(); }
}
if(data != null && slots[15] != null) {
int freq = ISatChip.getFreqS(slots[15]); for (int i = 0; i < 15; i++) {
if (slots[i] == null) {
Satellite sat = data.getSatFromFreq(freq); slots[i] = new ItemStack(stack.getItem(), 1, stack.getItemDamage());
return;
int delay = 10 * 60 * 1000; }
}
if(sat instanceof SatelliteMiner) { }
SatelliteMiner miner = (SatelliteMiner) sat; private void ejectInto(int x, int y, int z) {
TileEntity te = worldObj.getTileEntity(x, y, z);
if(miner.lastOp + delay < System.currentTimeMillis()) {
if (te instanceof IInventory) {
EntityMinerRocket rocket = new EntityMinerRocket(worldObj); IInventory chest = (IInventory) te;
rocket.posX = xCoord + 0.5;
rocket.posY = 300; for (int i = 0; i < 15; i++) {
rocket.posZ = zCoord + 0.5; if (slots[i] != null) {
for (int j = 0; j < chest.getSizeInventory(); j++) {
rocket.satelliteClassName = miner.getClass().getName(); ItemStack sta = slots[i].copy();
sta.stackSize = 1;
rocket.getDataWatcher().updateObject(17, freq);
worldObj.spawnEntityInWorld(rocket); if (chest.getStackInSlot(j) != null && chest.getStackInSlot(j).isItemEqual(slots[i]) && ItemStack.areItemStackTagsEqual(chest.getStackInSlot(j), slots[i]) &&
miner.lastOp = System.currentTimeMillis(); chest.getStackInSlot(j).stackSize < chest.getStackInSlot(j).getMaxStackSize()) {
data.markDirty();
} slots[i].stackSize--;
}
} if (slots[i].stackSize <= 0)
slots[i] = null;
List<Entity> list = worldObj.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB.getBoundingBox(xCoord - 0.25 + 0.5, yCoord + 0.75, zCoord - 0.25 + 0.5, xCoord + 0.25 + 0.5, yCoord + 2, zCoord + 0.25 + 0.5));
chest.getStackInSlot(j).stackSize++;
for(Entity e : list) { return;
}
if(e instanceof EntityMinerRocket) { }
}
EntityMinerRocket rocket = (EntityMinerRocket) e; }
if(slots[15] != null && ISatChip.getFreqS(slots[15]) != rocket.getDataWatcher().getWatchableObjectInt(17)) { for (int i = 0; i < 15; i++) {
rocket.setDead(); if (slots[i] != null) {
ExplosionNukeSmall.explode(worldObj, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, ExplosionNukeSmall.PARAMS_TOTS); for (int j = 0; j < chest.getSizeInventory(); j++) {
break; ItemStack sta = slots[i].copy();
} sta.stackSize = 1;
if(rocket.getDataWatcher().getWatchableObjectInt(16) == 1 && rocket.timer == 50) { if (chest.getStackInSlot(j) == null && chest.isItemValidForSlot(j, sta)) {
unloadCargo(rocket.satelliteClassName); slots[i].stackSize--;
}
} if (slots[i].stackSize <= 0)
} slots[i] = null;
ejectInto(xCoord + 2, yCoord, zCoord); chest.setInventorySlotContents(j, sta);
ejectInto(xCoord - 2, yCoord, zCoord); return;
ejectInto(xCoord, yCoord, zCoord + 2); }
ejectInto(xCoord, yCoord, zCoord - 2); }
} }
} }
}
static Random rand = new Random(); }
private void unloadCargo(String satelliteClassName) { AxisAlignedBB bb = null;
int items = rand.nextInt(6) + 10;
@Override
WeightedRandomObject[] cargo = SatelliteMinerCargoRegistry.getCargo(satelliteClassName); public AxisAlignedBB getRenderBoundingBox() {
if (bb == null) {
for(int i = 0; i < items; i++) { bb = AxisAlignedBB.getBoundingBox(
xCoord - 1,
ItemStack stack = ((WeightedRandomObject)WeightedRandom.getRandomItem(rand, cargo)).asStack(); yCoord,
addToInv(stack.copy()); zCoord - 1,
} xCoord + 2,
} yCoord + 1,
zCoord + 2
private void addToInv(ItemStack stack) { );
}
for(int i = 0; i < 15; i++) {
return bb;
if(slots[i] != null && slots[i].getItem() == stack.getItem() && slots[i].getItemDamage() == stack.getItemDamage() && slots[i].stackSize < slots[i].getMaxStackSize()) { }
int toAdd = Math.min(slots[i].getMaxStackSize() - slots[i].stackSize, stack.stackSize); @Override
@SideOnly(Side.CLIENT)
slots[i].stackSize += toAdd; public double getMaxRenderDistanceSquared() {
stack.stackSize -= toAdd; return 65536.0D;
}
if(stack.stackSize <= 0) return;
} @Override
} public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new ContainerSatDock(player.inventory, this);
for(int i = 0; i < 15; i++) { }
if(slots[i] == null) { @Override
slots[i] = new ItemStack(stack.getItem(), 1, stack.getItemDamage()); @SideOnly(Side.CLIENT)
return; public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
} return new GUISatDock(player.inventory, this);
} }
}
private void ejectInto(int x, int y, int z) {
TileEntity te = worldObj.getTileEntity(x, y, z);
if(te instanceof IInventory) {
IInventory chest = (IInventory)te;
for(int i = 0; i < 15; i++) {
if(slots[i] != null) {
for(int j = 0; j < chest.getSizeInventory(); j++) {
ItemStack sta = slots[i].copy();
sta.stackSize = 1;
if(chest.getStackInSlot(j) != null && chest.getStackInSlot(j).isItemEqual(slots[i]) && ItemStack.areItemStackTagsEqual(chest.getStackInSlot(j), slots[i]) &&
chest.getStackInSlot(j).stackSize < chest.getStackInSlot(j).getMaxStackSize()) {
slots[i].stackSize--;
if(slots[i].stackSize <= 0)
slots[i] = null;
chest.getStackInSlot(j).stackSize++;
return;
}
}
}
}
for(int i = 0; i < 15; i++) {
if(slots[i] != null) {
for(int j = 0; j < chest.getSizeInventory(); j++) {
ItemStack sta = slots[i].copy();
sta.stackSize = 1;
if(chest.getStackInSlot(j) == null && chest.isItemValidForSlot(j, sta)) {
slots[i].stackSize--;
if(slots[i].stackSize <= 0)
slots[i] = null;
chest.setInventorySlotContents(j, sta);
return;
}
}
}
}
}
}
AxisAlignedBB bb = null;
@Override
public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) {
bb = AxisAlignedBB.getBoundingBox(
xCoord - 1,
yCoord,
zCoord - 1,
xCoord + 2,
yCoord + 1,
zCoord + 2
);
}
return bb;
}
@Override
@SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() {
return 65536.0D;
}
@Override
public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new ContainerSatDock(player.inventory, this);
}
@Override
@SideOnly(Side.CLIENT)
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new GUISatDock(player.inventory, this);
}
} }