Skip to content

Instantly share code, notes, and snippets.

@ForsakenHarmony
Created January 23, 2016 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ForsakenHarmony/e19ca8c154f22c9fd17d to your computer and use it in GitHub Desktop.
Save ForsakenHarmony/e19ca8c154f22c9fd17d to your computer and use it in GitHub Desktop.
package com.icekat.thercmod.items;
import com.icekat.thercmod.ClientTickHandler;
import com.icekat.thercmod.RCM_Main;
import com.icekat.thercmod.network.PacketHandler;
import com.icekat.thercmod.network.SimplePacket;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameData;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class RCM_ItemRemoteControl4Ch extends RCM_BaseItem {
public static boolean state;
public static String name;
static {
name = "remotecontrol4ch";
}
public RCM_ItemRemoteControl4Ch() {
super(name);
this.maxStackSize = 1;
}
@Override
public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int useRemaining) {
String name = GameData.getItemRegistry().getNameForObject(this).toString();
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("active") && stack.getTagCompound().getBoolean("active")) {
return new ModelResourceLocation(name + "_on", "inventory");
}
return new ModelResourceLocation(name, "inventory");
}
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
if (world.isRemote) {
state = !state;
PacketHandler.net.sendToAll(new SimplePacket.SimpleMessage("Hello World, remote4ch: " + (state ? "On" : "Off")));
if (itemstack.getTagCompound() == null) {
itemstack.setTagCompound(new NBTTagCompound());
}
itemstack.getTagCompound().setBoolean("active", state);
ClientTickHandler.remoteActive8Ch = state;
}
return itemstack;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment