mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Added satellite managing commands, fixed some satellite map storage stuff
This commit is contained in:
parent
a22a68744c
commit
ccb91d98bf
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,5 +1,6 @@
|
|||||||
package com.hbm.main;
|
package com.hbm.main;
|
||||||
|
|
||||||
|
import com.hbm.commands.CommandSatellites;
|
||||||
import net.minecraft.block.BlockDispenser;
|
import net.minecraft.block.BlockDispenser;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||||
@ -926,6 +927,7 @@ public class MainRegistry {
|
|||||||
SiegeOrchestrator.createGameRules(world);
|
SiegeOrchestrator.createGameRules(world);
|
||||||
event.registerServerCommand(new CommandReloadRecipes());
|
event.registerServerCommand(new CommandReloadRecipes());
|
||||||
event.registerServerCommand(new CommandDebugChunkLoad());
|
event.registerServerCommand(new CommandDebugChunkLoad());
|
||||||
|
event.registerServerCommand(new CommandSatellites());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|||||||
@ -12,6 +12,17 @@ public class SatelliteSavedData extends WorldSavedData {
|
|||||||
|
|
||||||
public final HashMap<Integer, Satellite> sats = new HashMap<>();
|
public final HashMap<Integer, Satellite> sats = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor used for deserialization
|
||||||
|
* @param name - Map data name
|
||||||
|
*/
|
||||||
|
public SatelliteSavedData(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for satellites map data.
|
||||||
|
*/
|
||||||
public SatelliteSavedData() {
|
public SatelliteSavedData() {
|
||||||
super("satellites");
|
super("satellites");
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
@ -62,7 +73,6 @@ public class SatelliteSavedData extends WorldSavedData {
|
|||||||
worldObj.perWorldStorage.setData("satellites", new SatelliteSavedData());
|
worldObj.perWorldStorage.setData("satellites", new SatelliteSavedData());
|
||||||
|
|
||||||
data = (SatelliteSavedData)worldObj.perWorldStorage.loadData(SatelliteSavedData.class, "satellites");
|
data = (SatelliteSavedData)worldObj.perWorldStorage.loadData(SatelliteSavedData.class, "satellites");
|
||||||
data.markDirty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@ -28,8 +28,6 @@ import net.minecraft.world.World;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TileEntityMachineSatDock extends TileEntity implements ISidedInventory, IGUIProvider {
|
public class TileEntityMachineSatDock extends TileEntity implements ISidedInventory, IGUIProvider {
|
||||||
private SatelliteSavedData data;
|
|
||||||
|
|
||||||
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};
|
||||||
@ -182,8 +180,7 @@ public class TileEntityMachineSatDock extends TileEntity implements ISidedInvent
|
|||||||
@Override
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
if (!worldObj.isRemote) {
|
if (!worldObj.isRemote) {
|
||||||
if (data == null)
|
SatelliteSavedData data = SatelliteSavedData.getData(worldObj);
|
||||||
data = SatelliteSavedData.getData(worldObj);
|
|
||||||
|
|
||||||
if (slots[15] != null) {
|
if (slots[15] != null) {
|
||||||
int freq = ISatChip.getFreqS(slots[15]);
|
int freq = ISatChip.getFreqS(slots[15]);
|
||||||
|
|||||||
@ -19,8 +19,6 @@ import net.minecraft.tileentity.TileEntity;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class TileEntityMachineSatLinker extends TileEntity implements ISidedInventory, IGUIProvider {
|
public class TileEntityMachineSatLinker extends TileEntity implements ISidedInventory, IGUIProvider {
|
||||||
private SatelliteSavedData satelliteData;
|
|
||||||
|
|
||||||
private ItemStack[] slots;
|
private ItemStack[] slots;
|
||||||
|
|
||||||
//public static final int maxFill = 64 * 3;
|
//public static final int maxFill = 64 * 3;
|
||||||
@ -176,9 +174,7 @@ public class TileEntityMachineSatLinker extends TileEntity implements ISidedInve
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(slots[2] != null && slots[2].getItem() instanceof ISatChip) {
|
if(slots[2] != null && slots[2].getItem() instanceof ISatChip) {
|
||||||
if(satelliteData == null) {
|
SatelliteSavedData satelliteData = SatelliteSavedData.getData(worldObj);
|
||||||
satelliteData = SatelliteSavedData.getData(worldObj);
|
|
||||||
}
|
|
||||||
int newId = worldObj.rand.nextInt(100000);
|
int newId = worldObj.rand.nextInt(100000);
|
||||||
if(!satelliteData.isFreqTaken(newId)) {
|
if(!satelliteData.isFreqTaken(newId)) {
|
||||||
ISatChip.setFreqS(slots[2], newId);
|
ISatChip.setFreqS(slots[2], newId);
|
||||||
|
|||||||
@ -604,6 +604,12 @@ chem.XENON=Linde Xenon Cycle
|
|||||||
chem.XENON_OXY=Boosted Linde Xenon Cycle
|
chem.XENON_OXY=Boosted Linde Xenon Cycle
|
||||||
chem.YELLOWCAKE=Yellowcake Production
|
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.amsBase=AMS Base (Deco)
|
||||||
container.amsEmitter=AMS Emitter (Deco)
|
container.amsEmitter=AMS Emitter (Deco)
|
||||||
container.amsLimiter=AMS Stabilizer (Deco)
|
container.amsLimiter=AMS Stabilizer (Deco)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user