mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Merge pull request #1123 from Toshayo/master
Satellites. Yeah. They're cool.
This commit is contained in:
commit
5c10417308
87
src/main/java/com/hbm/commands/CommandSatellites.java
Normal file
87
src/main/java/com/hbm/commands/CommandSatellites.java
Normal file
@ -0,0 +1,87 @@
|
||||
package com.hbm.commands;
|
||||
|
||||
import com.hbm.items.ISatChip;
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.saveddata.SatelliteSavedData;
|
||||
import com.hbm.saveddata.satellites.Satellite;
|
||||
import net.minecraft.command.CommandBase;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.ChatStyle;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandSatellites extends CommandBase {
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "ntmsatellites";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender iCommandSender) {
|
||||
return String.format(
|
||||
"%s/%s orbit %s- Launch the held satellite\n" +
|
||||
"%s/%s descend <frequency> %s- Deletes satellite by frequency.",
|
||||
EnumChatFormatting.GREEN, getCommandName(), EnumChatFormatting.LIGHT_PURPLE,
|
||||
EnumChatFormatting.GREEN, getCommandName(), EnumChatFormatting.LIGHT_PURPLE
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) {
|
||||
if(!(sender instanceof EntityPlayer)) {
|
||||
sender.addChatMessage(new ChatComponentTranslation( "commands.satellite.should_be_run_as_player").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
|
||||
return;
|
||||
}
|
||||
switch (args[0]) {
|
||||
case "orbit":
|
||||
EntityPlayer player = getCommandSenderAsPlayer(sender);
|
||||
if(player.getHeldItem().getItem() instanceof ISatChip && player.getHeldItem().getItem() != ModItems.sat_chip) {
|
||||
Satellite.orbit(
|
||||
player.worldObj,
|
||||
Satellite.getIDFromItem(player.getHeldItem().getItem()),
|
||||
ISatChip.getFreqS(player.getHeldItem()),
|
||||
player.posX, player.posY, player.posZ
|
||||
);
|
||||
player.getHeldItem().stackSize -= 1;
|
||||
sender.addChatMessage(new ChatComponentTranslation("commands.satellite.satellite_orbited").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN)));
|
||||
} else {
|
||||
sender.addChatMessage(new ChatComponentTranslation("commands.satellite.not_a_satellite").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
|
||||
}
|
||||
break;
|
||||
case "descend":
|
||||
int freq = parseInt(sender, args[1]);
|
||||
SatelliteSavedData data = SatelliteSavedData.getData(sender.getEntityWorld());
|
||||
if(data.sats.containsKey(freq)) {
|
||||
data.sats.remove(freq);
|
||||
data.markDirty();
|
||||
sender.addChatMessage(new ChatComponentTranslation( "commands.satellite.satellite_descended").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN)));
|
||||
} else {
|
||||
sender.addChatMessage(new ChatComponentTranslation( "commands.satellite.no_satellite").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public List addTabCompletionOptions(ICommandSender sender, String[] args) {
|
||||
if(!(sender instanceof EntityPlayer)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if(args.length < 1) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if(args.length == 1) {
|
||||
return getListOfStringsMatchingLastWord(args, "orbit", "descend");
|
||||
}
|
||||
if (args[0].equals("descend")) {
|
||||
return getListOfStringsFromIterableMatchingLastWord(args, SatelliteSavedData.getData(sender.getEntityWorld()).sats.keySet().stream().map(String::valueOf).collect(Collectors.toList()));
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,8 @@
|
||||
package com.hbm.inventory.container;
|
||||
|
||||
import com.hbm.inventory.SlotTakeOnly;
|
||||
import com.hbm.items.machine.ItemSatChip;
|
||||
import com.hbm.tileentity.machine.TileEntityMachineSatDock;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
@ -11,41 +12,42 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ContainerSatDock extends Container {
|
||||
|
||||
private TileEntityMachineSatDock diFurnace;
|
||||
private final TileEntityMachineSatDock tileSatelliteDock;
|
||||
|
||||
public ContainerSatDock(InventoryPlayer invPlayer, TileEntityMachineSatDock tedf) {
|
||||
|
||||
diFurnace = tedf;
|
||||
public ContainerSatDock(InventoryPlayer invPlayer, TileEntityMachineSatDock tesd) {
|
||||
tileSatelliteDock = tesd;
|
||||
|
||||
//Storage
|
||||
this.addSlotToContainer(new Slot(tedf, 0, 62, 17));
|
||||
this.addSlotToContainer(new Slot(tedf, 1, 80, 17));
|
||||
this.addSlotToContainer(new Slot(tedf, 2, 98, 17));
|
||||
this.addSlotToContainer(new Slot(tedf, 3, 116, 17));
|
||||
this.addSlotToContainer(new Slot(tedf, 4, 134, 17));
|
||||
this.addSlotToContainer(new Slot(tedf, 5, 62, 35));
|
||||
this.addSlotToContainer(new Slot(tedf, 6, 80, 35));
|
||||
this.addSlotToContainer(new Slot(tedf, 7, 98, 35));
|
||||
this.addSlotToContainer(new Slot(tedf, 8, 116, 35));
|
||||
this.addSlotToContainer(new Slot(tedf, 9, 134, 35));
|
||||
this.addSlotToContainer(new Slot(tedf, 10, 62, 53));
|
||||
this.addSlotToContainer(new Slot(tedf, 11, 80, 53));
|
||||
this.addSlotToContainer(new Slot(tedf, 12, 98, 53));
|
||||
this.addSlotToContainer(new Slot(tedf, 13, 116, 53));
|
||||
this.addSlotToContainer(new Slot(tedf, 14, 134, 53));
|
||||
this.addSlotToContainer(new SlotTakeOnly(tesd, 0, 62, 17));
|
||||
this.addSlotToContainer(new SlotTakeOnly(tesd, 1, 80, 17));
|
||||
this.addSlotToContainer(new SlotTakeOnly(tesd, 2, 98, 17));
|
||||
this.addSlotToContainer(new SlotTakeOnly(tesd, 3, 116, 17));
|
||||
this.addSlotToContainer(new SlotTakeOnly(tesd, 4, 134, 17));
|
||||
this.addSlotToContainer(new SlotTakeOnly(tesd, 5, 62, 35));
|
||||
this.addSlotToContainer(new SlotTakeOnly(tesd, 6, 80, 35));
|
||||
this.addSlotToContainer(new SlotTakeOnly(tesd, 7, 98, 35));
|
||||
this.addSlotToContainer(new SlotTakeOnly(tesd, 8, 116, 35));
|
||||
this.addSlotToContainer(new SlotTakeOnly(tesd, 9, 134, 35));
|
||||
this.addSlotToContainer(new SlotTakeOnly(tesd, 10, 62, 53));
|
||||
this.addSlotToContainer(new SlotTakeOnly(tesd, 11, 80, 53));
|
||||
this.addSlotToContainer(new SlotTakeOnly(tesd, 12, 98, 53));
|
||||
this.addSlotToContainer(new SlotTakeOnly(tesd, 13, 116, 53));
|
||||
this.addSlotToContainer(new SlotTakeOnly(tesd, 14, 134, 53));
|
||||
//Chip
|
||||
this.addSlotToContainer(new Slot(tedf, 15, 26, 35));
|
||||
this.addSlotToContainer(new Slot(tesd, 15, 26, 35) {
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return stack.getItem() instanceof ItemSatChip;
|
||||
}
|
||||
});
|
||||
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
for(int j = 0; j < 9; j++)
|
||||
{
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 9; j++) {
|
||||
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < 9; i++)
|
||||
{
|
||||
for(int i = 0; i < 9; i++) {
|
||||
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 142));
|
||||
}
|
||||
}
|
||||
@ -56,33 +58,25 @@ public class ContainerSatDock extends Container {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int par2)
|
||||
{
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int par2) {
|
||||
ItemStack var3 = null;
|
||||
Slot var4 = (Slot) this.inventorySlots.get(par2);
|
||||
|
||||
if (var4 != null && var4.getHasStack())
|
||||
{
|
||||
if (var4 != null && var4.getHasStack()) {
|
||||
ItemStack var5 = var4.getStack();
|
||||
var3 = var5.copy();
|
||||
|
||||
if (par2 <= 15) {
|
||||
if (!this.mergeItemStack(var5, 16, this.inventorySlots.size(), true))
|
||||
{
|
||||
if (!this.mergeItemStack(var5, 16, this.inventorySlots.size(), true)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(var5, 0, 15, false))
|
||||
{
|
||||
return null;
|
||||
} else if (!this.mergeItemStack(var5, 0, 15, false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (var5.stackSize == 0)
|
||||
{
|
||||
var4.putStack((ItemStack) null);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (var5.stackSize == 0) {
|
||||
var4.putStack(null);
|
||||
} else {
|
||||
var4.onSlotChanged();
|
||||
}
|
||||
}
|
||||
@ -92,6 +86,6 @@ public class ContainerSatDock extends Container {
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return diFurnace.isUseableByPlayer(player);
|
||||
return tileSatelliteDock.isUseableByPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,24 +1,22 @@
|
||||
package com.hbm.inventory.gui;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.inventory.container.ContainerSatDock;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.tileentity.machine.TileEntityMachineSatDock;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class GUISatDock extends GuiInfoContainer {
|
||||
|
||||
public static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_dock.png");
|
||||
private TileEntityMachineSatDock diFurnace;
|
||||
public static final ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_dock.png");
|
||||
private final TileEntityMachineSatDock tileSatelliteDock;
|
||||
|
||||
public GUISatDock(InventoryPlayer invPlayer, TileEntityMachineSatDock tedf) {
|
||||
super(new ContainerSatDock(invPlayer, tedf));
|
||||
diFurnace = tedf;
|
||||
public GUISatDock(InventoryPlayer invPlayer, TileEntityMachineSatDock tesd) {
|
||||
super(new ContainerSatDock(invPlayer, tesd));
|
||||
tileSatelliteDock = tesd;
|
||||
|
||||
this.xSize = 176;
|
||||
this.ySize = 168;
|
||||
@ -36,10 +34,10 @@ public class GUISatDock extends GuiInfoContainer {
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int i, int j) {
|
||||
String name = this.diFurnace.hasCustomInventoryName() ? this.diFurnace.getInventoryName() : I18n.format(this.diFurnace.getInventoryName());
|
||||
String name = this.tileSatelliteDock.hasCustomInventoryName() ? this.tileSatelliteDock.getInventoryName() : I18n.format(this.tileSatelliteDock.getInventoryName());
|
||||
|
||||
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);
|
||||
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
|
||||
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 0x404040);
|
||||
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 0x404040);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.hbm.main;
|
||||
|
||||
import com.hbm.commands.CommandSatellites;
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
@ -926,6 +927,7 @@ public class MainRegistry {
|
||||
SiegeOrchestrator.createGameRules(world);
|
||||
event.registerServerCommand(new CommandReloadRecipes());
|
||||
event.registerServerCommand(new CommandDebugChunkLoad());
|
||||
event.registerServerCommand(new CommandSatellites());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@ -1,35 +1,38 @@
|
||||
package com.hbm.saveddata;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.hbm.saveddata.satellites.Satellite;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldSavedData;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class SatelliteSavedData extends WorldSavedData {
|
||||
|
||||
public HashMap<Integer, Satellite> sats = new HashMap();
|
||||
public final HashMap<Integer, Satellite> sats = new HashMap<>();
|
||||
|
||||
public SatelliteSavedData(String p_i2141_1_) {
|
||||
super(p_i2141_1_);
|
||||
/**
|
||||
* Constructor used for deserialization
|
||||
* @param name - Map data name
|
||||
*/
|
||||
public SatelliteSavedData(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public SatelliteSavedData()
|
||||
{
|
||||
/**
|
||||
* Default constructor for satellites map data.
|
||||
*/
|
||||
public SatelliteSavedData() {
|
||||
super("satellites");
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public boolean isFreqTaken(int freq) {
|
||||
|
||||
return getSatFromFreq(freq) != null;
|
||||
}
|
||||
|
||||
public Satellite getSatFromFreq(int freq) {
|
||||
|
||||
return sats.get(freq);
|
||||
}
|
||||
|
||||
@ -38,7 +41,6 @@ public class SatelliteSavedData extends WorldSavedData {
|
||||
int satCount = nbt.getInteger("satCount");
|
||||
|
||||
for(int i = 0; i < satCount; i++) {
|
||||
|
||||
Satellite sat = Satellite.create(nbt.getInteger("sat_id_" + i));
|
||||
sat.readFromNBT((NBTTagCompound) nbt.getTag("sat_data_" + i));
|
||||
|
||||
@ -55,7 +57,6 @@ public class SatelliteSavedData extends WorldSavedData {
|
||||
int i = 0;
|
||||
|
||||
for(Entry<Integer, Satellite> struct : sats.entrySet()) {
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
struct.getValue().writeToNBT(data);
|
||||
|
||||
@ -67,7 +68,6 @@ public class SatelliteSavedData extends WorldSavedData {
|
||||
}
|
||||
|
||||
public static SatelliteSavedData getData(World worldObj) {
|
||||
|
||||
SatelliteSavedData data = (SatelliteSavedData)worldObj.perWorldStorage.loadData(SatelliteSavedData.class, "satellites");
|
||||
if(data == null) {
|
||||
worldObj.perWorldStorage.setData("satellites", new SatelliteSavedData());
|
||||
@ -77,5 +77,4 @@ public class SatelliteSavedData extends WorldSavedData {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,23 +1,22 @@
|
||||
package com.hbm.saveddata.satellites;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.saveddata.SatelliteSavedData;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Satellite {
|
||||
|
||||
public static List<Class> satellites = new ArrayList();
|
||||
public static HashMap<Item, Class> itemToClass = new HashMap();
|
||||
public static final List<Class<? extends Satellite>> satellites = new ArrayList<>();
|
||||
public static final HashMap<Item, Class<? extends Satellite>> itemToClass = new HashMap<>();
|
||||
|
||||
public static enum InterfaceActions {
|
||||
public enum InterfaceActions {
|
||||
HAS_MAP, //lets the interface display loaded chunks
|
||||
CAN_CLICK, //enables onClick events
|
||||
SHOW_COORDS, //enables coordinates as a mouse tooltip
|
||||
@ -25,18 +24,18 @@ public abstract class Satellite {
|
||||
HAS_ORES //like HAS_MAP but only shows ores
|
||||
}
|
||||
|
||||
public static enum CoordActions {
|
||||
public enum CoordActions {
|
||||
HAS_Y //enables the Y-coord field which is disabled by default
|
||||
}
|
||||
|
||||
public static enum Interfaces {
|
||||
public enum Interfaces {
|
||||
NONE, //does not interact with any sat interface (i.e. asteroid miners)
|
||||
SAT_PANEL, //allows to interact with the sat interface panel (for graphical applications)
|
||||
SAT_COORD //allows to interact with the sat coord remote (for teleportation or other coord related actions)
|
||||
}
|
||||
|
||||
public List<InterfaceActions> ifaceAcs = new ArrayList();
|
||||
public List<CoordActions> coordAcs = new ArrayList();
|
||||
public List<InterfaceActions> ifaceAcs = new ArrayList<>();
|
||||
public List<CoordActions> coordAcs = new ArrayList<>();
|
||||
public Interfaces satIface = Interfaces.NONE;
|
||||
|
||||
public static void register() {
|
||||
@ -64,10 +63,13 @@ public abstract class Satellite {
|
||||
}
|
||||
|
||||
public static void orbit(World world, int id, int freq, double x, double y, double z) {
|
||||
|
||||
if(world.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
Satellite sat = create(id);
|
||||
|
||||
if(sat != null && !world.isRemote) {
|
||||
if(sat != null) {
|
||||
SatelliteSavedData data = SatelliteSavedData.getData(world);
|
||||
data.sats.put(freq, sat);
|
||||
sat.onOrbit(world, x, y, z);
|
||||
@ -76,25 +78,22 @@ public abstract class Satellite {
|
||||
}
|
||||
|
||||
public static Satellite create(int id) {
|
||||
|
||||
Satellite sat = null;
|
||||
|
||||
try {
|
||||
Class c = satellites.get(id);
|
||||
sat = (Satellite) c.newInstance();
|
||||
} catch(Exception ex) {
|
||||
|
||||
Class<? extends Satellite> c = satellites.get(id);
|
||||
sat = c.newInstance();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return sat;
|
||||
}
|
||||
|
||||
public static int getIDFromItem(Item item) {
|
||||
|
||||
Class<? extends Satellite> sat = itemToClass.get(item);
|
||||
int i = satellites.indexOf(sat);
|
||||
|
||||
return i;
|
||||
|
||||
return satellites.indexOf(sat);
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
|
||||
@ -13,7 +13,6 @@ import com.hbm.util.WeightedRandomObject;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@ -27,15 +26,16 @@ import net.minecraft.util.WeightedRandom;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class TileEntityMachineSatDock extends TileEntity implements ISidedInventory, IGUIProvider {
|
||||
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 AxisAlignedBB renderBoundingBox;
|
||||
|
||||
public TileEntityMachineSatDock() {
|
||||
slots = new ItemStack[16];
|
||||
}
|
||||
@ -177,21 +177,12 @@ public class TileEntityMachineSatDock extends TileEntity implements ISidedInvent
|
||||
return true;
|
||||
}
|
||||
|
||||
SatelliteSavedData data = null;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (!worldObj.isRemote) {
|
||||
if (data == null)
|
||||
data = (SatelliteSavedData) worldObj.perWorldStorage.loadData(SatelliteSavedData.class, "satellites");
|
||||
SatelliteSavedData data = SatelliteSavedData.getData(worldObj);
|
||||
|
||||
if (data == null) {
|
||||
worldObj.perWorldStorage.setData("satellites", new SatelliteSavedData());
|
||||
data = (SatelliteSavedData) worldObj.perWorldStorage.loadData(SatelliteSavedData.class, "satellites");
|
||||
}
|
||||
data.markDirty();
|
||||
|
||||
if (data != null && slots[15] != null) {
|
||||
if (slots[15] != null) {
|
||||
int freq = ISatChip.getFreqS(slots[15]);
|
||||
|
||||
Satellite sat = data.getSatFromFreq(freq);
|
||||
@ -215,22 +206,23 @@ public class TileEntityMachineSatDock extends TileEntity implements ISidedInvent
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<EntityMinerRocket> 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),
|
||||
entity -> entity instanceof EntityMinerRocket
|
||||
);
|
||||
|
||||
for (Entity e : list) {
|
||||
if (e instanceof EntityMinerRocket) {
|
||||
EntityMinerRocket rocket = (EntityMinerRocket) e;
|
||||
for (EntityMinerRocket rocket : list) {
|
||||
if (slots[15] != null && ISatChip.getFreqS(slots[15]) != rocket.getDataWatcher().getWatchableObjectInt(17)) {
|
||||
rocket.setDead();
|
||||
ExplosionNukeSmall.explode(worldObj, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, ExplosionNukeSmall.PARAMS_TOTS);
|
||||
break;
|
||||
}
|
||||
|
||||
if (slots[15] != null && ISatChip.getFreqS(slots[15]) != rocket.getDataWatcher().getWatchableObjectInt(17)) {
|
||||
rocket.setDead();
|
||||
ExplosionNukeSmall.explode(worldObj, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, ExplosionNukeSmall.PARAMS_TOTS);
|
||||
break;
|
||||
}
|
||||
|
||||
if (rocket.getDataWatcher().getWatchableObjectInt(16) == 1 && rocket.timer == 50) {
|
||||
Satellite sat = data.getSatFromFreq(ISatChip.getFreqS(slots[15]));
|
||||
unloadCargo((SatelliteMiner) sat);
|
||||
}
|
||||
if (rocket.getDataWatcher().getWatchableObjectInt(16) == 1 && rocket.timer == 50) {
|
||||
Satellite sat = data.getSatFromFreq(ISatChip.getFreqS(slots[15]));
|
||||
unloadCargo((SatelliteMiner) sat);
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,15 +233,13 @@ public class TileEntityMachineSatDock extends TileEntity implements ISidedInvent
|
||||
}
|
||||
}
|
||||
|
||||
static final Random rand = new Random();
|
||||
|
||||
private void unloadCargo(SatelliteMiner satellite) {
|
||||
int items = rand.nextInt(6) + 10;
|
||||
int itemAmount = worldObj.rand.nextInt(6) + 10;
|
||||
|
||||
WeightedRandomObject[] cargo = satellite.getCargo();
|
||||
|
||||
for (int i = 0; i < items; i++) {
|
||||
ItemStack stack = ((WeightedRandomObject) WeightedRandom.getRandomItem(rand, cargo)).asStack();
|
||||
for (int i = 0; i < itemAmount; i++) {
|
||||
ItemStack stack = ((WeightedRandomObject) WeightedRandom.getRandomItem(worldObj.rand, cargo)).asStack();
|
||||
addToInv(stack.copy());
|
||||
}
|
||||
}
|
||||
@ -322,12 +312,10 @@ public class TileEntityMachineSatDock extends TileEntity implements ISidedInvent
|
||||
}
|
||||
}
|
||||
|
||||
AxisAlignedBB bb = null;
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
if (bb == null) {
|
||||
bb = AxisAlignedBB.getBoundingBox(
|
||||
if (renderBoundingBox == null) {
|
||||
renderBoundingBox = AxisAlignedBB.getBoundingBox(
|
||||
xCoord - 1,
|
||||
yCoord,
|
||||
zCoord - 1,
|
||||
@ -337,7 +325,7 @@ public class TileEntityMachineSatDock extends TileEntity implements ISidedInvent
|
||||
);
|
||||
}
|
||||
|
||||
return bb;
|
||||
return renderBoundingBox;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -3,6 +3,7 @@ package com.hbm.tileentity.machine;
|
||||
import com.hbm.inventory.container.ContainerMachineSatLinker;
|
||||
import com.hbm.inventory.gui.GUIMachineSatLinker;
|
||||
import com.hbm.items.ISatChip;
|
||||
import com.hbm.saveddata.SatelliteSavedData;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@ -18,8 +19,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TileEntityMachineSatLinker extends TileEntity implements ISidedInventory, IGUIProvider {
|
||||
|
||||
private ItemStack slots[];
|
||||
private ItemStack[] slots;
|
||||
|
||||
//public static final int maxFill = 64 * 3;
|
||||
|
||||
@ -45,21 +45,19 @@ public class TileEntityMachineSatLinker extends TileEntity implements ISidedInve
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i) {
|
||||
if(slots[i] != null)
|
||||
{
|
||||
if(slots[i] != null) {
|
||||
ItemStack itemStack = slots[i];
|
||||
slots[i] = null;
|
||||
return itemStack;
|
||||
} else {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemStack) {
|
||||
slots[i] = itemStack;
|
||||
if(itemStack != null && itemStack.stackSize > getInventoryStackLimit())
|
||||
{
|
||||
if(itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
|
||||
itemStack.stackSize = getInventoryStackLimit();
|
||||
}
|
||||
}
|
||||
@ -85,11 +83,10 @@ public class TileEntityMachineSatLinker extends TileEntity implements ISidedInve
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
if(worldObj.getTileEntity(xCoord, yCoord, zCoord) != this)
|
||||
{
|
||||
if(worldObj.getTileEntity(xCoord, yCoord, zCoord) != this) {
|
||||
return false;
|
||||
}else{
|
||||
return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <=64;
|
||||
} else {
|
||||
return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 64;
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,17 +102,14 @@ public class TileEntityMachineSatLinker extends TileEntity implements ISidedInve
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j) {
|
||||
if(slots[i] != null)
|
||||
{
|
||||
if(slots[i].stackSize <= j)
|
||||
{
|
||||
if(slots[i] != null) {
|
||||
if(slots[i].stackSize <= j) {
|
||||
ItemStack itemStack = slots[i];
|
||||
slots[i] = null;
|
||||
return itemStack;
|
||||
}
|
||||
ItemStack itemStack1 = slots[i].splitStack(j);
|
||||
if (slots[i].stackSize == 0)
|
||||
{
|
||||
if (slots[i].stackSize == 0) {
|
||||
slots[i] = null;
|
||||
}
|
||||
|
||||
@ -132,12 +126,10 @@ public class TileEntityMachineSatLinker extends TileEntity implements ISidedInve
|
||||
|
||||
slots = new ItemStack[getSizeInventory()];
|
||||
|
||||
for(int i = 0; i < list.tagCount(); i++)
|
||||
{
|
||||
for(int i = 0; i < list.tagCount(); i++) {
|
||||
NBTTagCompound nbt1 = list.getCompoundTagAt(i);
|
||||
byte b0 = nbt1.getByte("slot");
|
||||
if(b0 >= 0 && b0 < slots.length)
|
||||
{
|
||||
if(b0 >= 0 && b0 < slots.length) {
|
||||
slots[b0] = ItemStack.loadItemStackFromNBT(nbt1);
|
||||
}
|
||||
}
|
||||
@ -148,10 +140,8 @@ public class TileEntityMachineSatLinker extends TileEntity implements ISidedInve
|
||||
super.writeToNBT(nbt);
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
||||
for(int i = 0; i < slots.length; i++)
|
||||
{
|
||||
if(slots[i] != null)
|
||||
{
|
||||
for(int i = 0; i < slots.length; i++) {
|
||||
if(slots[i] != null) {
|
||||
NBTTagCompound nbt1 = new NBTTagCompound();
|
||||
nbt1.setByte("slot", (byte)i);
|
||||
slots[i].writeToNBT(nbt1);
|
||||
@ -162,8 +152,7 @@ public class TileEntityMachineSatLinker extends TileEntity implements ISidedInve
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int p_94128_1_)
|
||||
{
|
||||
public int[] getAccessibleSlotsFromSide(int p_94128_1_) {
|
||||
return p_94128_1_ == 0 ? slots_bottom : (p_94128_1_ == 1 ? slots_top : slots_side);
|
||||
}
|
||||
|
||||
@ -179,15 +168,17 @@ public class TileEntityMachineSatLinker extends TileEntity implements ISidedInve
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
if(!worldObj.isRemote)
|
||||
{
|
||||
if(!worldObj.isRemote) {
|
||||
if(slots[0] != null && slots[1] != null && slots[0].getItem() instanceof ISatChip && slots[1].getItem() instanceof ISatChip) {
|
||||
ISatChip.setFreqS(slots[1], ISatChip.getFreqS(slots[0]));
|
||||
}
|
||||
|
||||
if(slots[2] != null && slots[2].getItem() instanceof ISatChip) {
|
||||
ISatChip.setFreqS(slots[2], worldObj.rand.nextInt(100000));
|
||||
SatelliteSavedData satelliteData = SatelliteSavedData.getData(worldObj);
|
||||
int newId = worldObj.rand.nextInt(100000);
|
||||
if(!satelliteData.isFreqTaken(newId)) {
|
||||
ISatChip.setFreqS(slots[2], newId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -604,6 +604,12 @@ chem.XENON=Linde Xenon Cycle
|
||||
chem.XENON_OXY=Boosted Linde Xenon Cycle
|
||||
chem.YELLOWCAKE=Yellowcake Production
|
||||
|
||||
commands.satellite.no_satellite=No satellite using this frequency found!
|
||||
commands.satellite.not_a_satellite=The held item is not a satellite!
|
||||
commands.satellite.satellite_descended=Satellite successfully descended.
|
||||
commands.satellite.satellite_orbited=Satellite launched.
|
||||
commands.satellite.should_be_run_as_player=This command should be run by a player!
|
||||
|
||||
container.amsBase=AMS Base (Deco)
|
||||
container.amsEmitter=AMS Emitter (Deco)
|
||||
container.amsLimiter=AMS Stabilizer (Deco)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user