Skip to content

Commit

Permalink
Merge pull request #13 from GTNewHorizons/feature/panel-memory-card
Browse files Browse the repository at this point in the history
Add information panel memory card
  • Loading branch information
Dream-Master authored Sep 1, 2022
2 parents 908d46c + d099096 commit 924a61e
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import shedar.mods.ic2.nuclearcontrol.items.ItemKitReactorSensor;
import shedar.mods.ic2.nuclearcontrol.items.ItemNuclearControlLight;
import shedar.mods.ic2.nuclearcontrol.items.ItemNuclearControlMain;
import shedar.mods.ic2.nuclearcontrol.items.ItemPanelMemoryCard;
import shedar.mods.ic2.nuclearcontrol.items.ItemRemoteMonitor;
import shedar.mods.ic2.nuclearcontrol.items.ItemTimeCard;
import shedar.mods.ic2.nuclearcontrol.items.ItemToolDigitalThermometer;
Expand Down Expand Up @@ -82,6 +83,7 @@ public class IC2NuclearControl {
public static boolean isThorfusionLoaded;
public String allowedAlarms;
public List<String> serverAllowedAlarms;
public static Item itemPanelMemoryCard;
public static Item itemToolThermometer;
public static Item itemToolDigitalThermometer;
public static Item itemRemoteSensorKit;
Expand Down Expand Up @@ -126,6 +128,7 @@ public class IC2NuclearControl {
protected void initBlocks() {
blockNuclearControlMain = new BlockNuclearControlMain();
blockNuclearControlLight = new BlockNuclearControlLight();
itemPanelMemoryCard = new ItemPanelMemoryCard().setUnlocalizedName("ItemPanelMemoryCard");
itemToolThermometer = new ItemToolThermometer().setUnlocalizedName("ItemToolThermometer");
itemToolDigitalThermometer = new ItemToolDigitalThermometer(1, 80, 80).setUnlocalizedName("ItemToolDigitalThermometer");
itemSensorLocationCard = new ItemCardReactorSensorLocation().setUnlocalizedName("ItemSensorLocationCard");
Expand All @@ -140,12 +143,13 @@ protected void initBlocks() {
itemRemoteSensorKit = new ItemKitReactorSensor().setUnlocalizedName("ItemRemoteSensorKit");
itemLiquidArrayLocationCard = new ItemCardLiquidArrayLocation().setUnlocalizedName("ItemLiquidArrayLocationCard");
item55ReactorCard = new ItemCard55Reactor().setUnlocalizedName("Item55ReactorCard");
itemRemoteMonitor = new ItemRemoteMonitor().setUnlocalizedName("remoteMonitor");
itemRemoteMonitor = new ItemRemoteMonitor().setUnlocalizedName("remoteMonitor");
}

protected void registerBlocks() {
GameRegistry.registerBlock(blockNuclearControlMain, ItemNuclearControlMain.class, "blockNuclearControlMain");
GameRegistry.registerBlock(blockNuclearControlLight, ItemNuclearControlLight.class,"blockNuclearControlLight");
GameRegistry.registerItem(itemPanelMemoryCard, "ItemPanelMemoryCard");
GameRegistry.registerItem(itemToolThermometer, "ItemToolThermometer");
GameRegistry.registerItem(itemToolDigitalThermometer, "ItemToolDigitalThermometer");
GameRegistry.registerItem(itemRemoteSensorKit, "ItemRemoteSensorKit");
Expand All @@ -160,7 +164,7 @@ protected void registerBlocks() {
GameRegistry.registerItem(itemTextCard, "ItemTextCard");
GameRegistry.registerItem(itemLiquidArrayLocationCard, "ItemLiquidArrayLocationCard");
GameRegistry.registerItem(item55ReactorCard, "Item55ReactorCard");
GameRegistry.registerItem(itemRemoteMonitor, "remoteMonitor");
GameRegistry.registerItem(itemRemoteMonitor, "remoteMonitor");
}

@EventHandler
Expand Down Expand Up @@ -188,7 +192,7 @@ public void preInit(FMLPreInitializationEvent event) {
FMLCommonHandler.instance().bus().register(ClientTickHandler.instance);
}
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
CrossModLoader.preinit();
CrossModLoader.preinit();
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package shedar.mods.ic2.nuclearcontrol.items;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import shedar.mods.ic2.nuclearcontrol.IC2NuclearControl;
import shedar.mods.ic2.nuclearcontrol.tileentities.TileEntityInfoPanel;
import shedar.mods.ic2.nuclearcontrol.utils.TextureResolver;

import java.util.List;

public class ItemPanelMemoryCard extends Item {

public ItemPanelMemoryCard() {
super();
setMaxStackSize(1);
setCreativeTab(IC2NuclearControl.tabIC2NC);
setTextureName(TextureResolver.getItemTexture("panelMemoryCard"));
}

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack itemStack, EntityPlayer player,
List info, boolean advanced) {
NBTTagCompound nbt = itemStack.getTagCompound();
if (nbt != null) {
// Count saved settings for existing cards
int cardsSaved = 0;
for (int i = 0; i < 4; i++) {
String key = "dSettings";
if (i > 0) key += i;
if (nbt.hasKey(key)) {
NBTTagList settings = nbt.getTagList(key, Constants.NBT.TAG_COMPOUND);
if (settings.tagCount() > 0)
cardsSaved++;
}
}

if (nbt.hasKey("rotateHor"))
info.add("Contains panel metadata");
if (cardsSaved > 0)
info.add("Contains settings for " + cardsSaved + " card(s)");
}
}

@Override
public boolean onItemUseFirst(ItemStack itemStack, EntityPlayer player,
World world, int x, int y, int z, int side,
float hitX, float hitY, float hitZ) {
boolean isServer = !world.isRemote;
if (!isServer)
return false;

TileEntity panel = world.getTileEntity(x, y, z);
if (panel instanceof TileEntityInfoPanel) {
if (player.isSneaking()) {
((TileEntityInfoPanel) panel).saveDisplaySettingsToCard(itemStack);
messagePlayer(player, "Panel settings saved");
} else {
NBTTagCompound panelNBT = itemStack.getTagCompound();
if (panelNBT == null)
return false;
((TileEntityInfoPanel) panel).readDisplaySettingsFromCard(itemStack);
messagePlayer(player, "Panel settings applied");
}
} else {
if (player.isSneaking()) {
itemStack.setTagCompound(null);
messagePlayer(player, "Settings cleared.");
}
return false;
}

return true;
}

protected void messagePlayer(EntityPlayer entityplayer, String text) {
entityplayer.addChatComponentMessage(new ChatComponentText(text));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,30 @@ protected void readDisplaySettings(NBTTagCompound nbttagcompound) {
textRotation = nbttagcompound.getByte("textRotation");
}

@Override
public void readDisplaySettingsFromCard(ItemStack item) {
NBTTagCompound nbt = item.getTagCompound();

setDeserializedDisplaySettings(nbt, "dSettings1", SLOT_CARD1);
setDeserializedDisplaySettings(nbt, "dSettings2", SLOT_CARD2);
setDeserializedDisplaySettings(nbt, "dSettings3", SLOT_CARD3);

// Compat for settings for one card from normal panel
setDeserializedDisplaySettings(nbt, "dSettings", SLOT_CARD1);

// If one of these keys exists, all should
if (nbt.hasKey("rotateHor")) {
setRotateHor(nbt.getByte("rotateHor"));
setRotateVert(nbt.getByte("rotateVert"));
setThickness(nbt.getByte("thickness"));
setPowerMode(nbt.getByte("powerMode"));
setTransparencyMode(nbt.getByte("transparencyMode"));
setTextRotation(nbt.getByte("textRotation"));
setColorText(nbt.getInteger("colorText"));
setColorBackground(nbt.getInteger("colorBackground"));
}
}

@Override
protected void postReadFromNBT() {
if (inventory[SLOT_CARD1] != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,26 @@ protected void deserializeDisplaySettings(NBTTagCompound nbttagcompound,
}
}

// Same as deserializeDisplaySettings, but uses setDisplaySettings
// to ensure values are properly updated
protected void setDeserializedDisplaySettings(NBTTagCompound nbttagcompound,
String tagName, byte slot) {
if (nbttagcompound.hasKey(tagName)) {
NBTTagList settingsList = nbttagcompound.getTagList(tagName,
Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < settingsList.tagCount(); i++) {
NBTTagCompound compound = settingsList.getCompoundTagAt(i);
try {
int value = compound.getInteger("value");
setDisplaySettings(slot, value);
} catch (IllegalArgumentException e) {
IC2NuclearControl.logger
.warn("Ivalid display settings for Information Panel");
}
}
}
}

protected void readDisplaySettings(NBTTagCompound nbttagcompound) {
deserializeDisplaySettings(nbttagcompound, "dSettings", SLOT_CARD);
if (nbttagcompound.hasKey("dSets")) {// v.1.3.2 compatibility
Expand All @@ -448,6 +468,14 @@ protected void readDisplaySettings(NBTTagCompound nbttagcompound) {
}
}

public void readDisplaySettingsFromCard(ItemStack item) {
NBTTagCompound nbt = item.getTagCompound();
setDeserializedDisplaySettings(nbt, "dSettings", SLOT_CARD);

// Compat for settings for one card from advanced panel
setDeserializedDisplaySettings(nbt, "dSettings1", SLOT_CARD);
}

@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
Expand Down Expand Up @@ -514,6 +542,14 @@ protected void saveDisplaySettings(NBTTagCompound nbttagcompound) {
nbttagcompound.setTag("dSettings", serializeSlotSettings(SLOT_CARD));
}

public void saveDisplaySettingsToCard(ItemStack item) {
NBTTagCompound nbt = new NBTTagCompound();
this.saveDisplaySettings(nbt);
nbt.setInteger("colorText", colorText);
nbt.setInteger("colorBackground", colorBackground);
item.setTagCompound(nbt);
}

@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/nuclearcontrol/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ nc.itemgroup.tab=Nuclear Control 2

#Internal Items
item.ItemToolThermometer.name=Thermometer
item.ItemPanelMemoryCard.name=Information Panel Memory Card
item.ItemToolDigitalThermometer.name=Digital Thermometer
item.ItemRemoteSensorKit.name=Remote Sensor Kit
item.ItemEnergySensorKit.name=Energy Sensor Kit
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 924a61e

Please sign in to comment.