mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-08-10 17:55:44 +00:00
locking loot blocks
This commit is contained in:
parent
3328da75e2
commit
f72cc804db
@ -14,9 +14,11 @@ import com.hbm.config.StructureConfig;
|
|||||||
import com.hbm.interfaces.IBomb;
|
import com.hbm.interfaces.IBomb;
|
||||||
import com.hbm.interfaces.ICopiable;
|
import com.hbm.interfaces.ICopiable;
|
||||||
import com.hbm.itempool.ItemPool;
|
import com.hbm.itempool.ItemPool;
|
||||||
|
import com.hbm.items.tool.ItemLock;
|
||||||
import com.hbm.lib.RefStrings;
|
import com.hbm.lib.RefStrings;
|
||||||
import com.hbm.main.MainRegistry;
|
import com.hbm.main.MainRegistry;
|
||||||
import com.hbm.tileentity.TileEntityLoadedBase;
|
import com.hbm.tileentity.TileEntityLoadedBase;
|
||||||
|
import com.hbm.tileentity.machine.TileEntityLockableBase;
|
||||||
import com.hbm.util.BufferUtil;
|
import com.hbm.util.BufferUtil;
|
||||||
import com.hbm.util.LootGenerator;
|
import com.hbm.util.LootGenerator;
|
||||||
import com.hbm.util.i18n.I18nUtil;
|
import com.hbm.util.i18n.I18nUtil;
|
||||||
@ -36,6 +38,7 @@ import net.minecraft.client.renderer.texture.IIconRegister;
|
|||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
@ -113,6 +116,11 @@ public class BlockWandLoot extends BlockContainer implements ILookOverlay, ITool
|
|||||||
text.add("Maximum items: " + loot.maxItems);
|
text.add("Maximum items: " + loot.maxItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(loot.lockCode != 0){
|
||||||
|
text.add("Container will be locked");
|
||||||
|
text.add("Lockpicking chance:" + loot.lockMod);
|
||||||
|
}
|
||||||
|
|
||||||
ILookOverlay.printGeneric(event, I18nUtil.resolveKey(getUnlocalizedName() + ".name"), 0xffff00, 0x404000, text);
|
ILookOverlay.printGeneric(event, I18nUtil.resolveKey(getUnlocalizedName() + ".name"), 0xffff00, 0x404000, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,6 +159,12 @@ public class BlockWandLoot extends BlockContainer implements ILookOverlay, ITool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ItemStack held = player.getHeldItem();
|
||||||
|
if(held != null && held.getItem() instanceof ItemLock){
|
||||||
|
loot.lockMod = (float) ((ItemLock)held.getItem()).lockMod;
|
||||||
|
loot.lockCode = ItemLock.getPins(held);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,6 +257,10 @@ public class BlockWandLoot extends BlockContainer implements ILookOverlay, ITool
|
|||||||
|
|
||||||
private float placedRotation;
|
private float placedRotation;
|
||||||
|
|
||||||
|
private float lockMod = 0;
|
||||||
|
private int lockCode = 0;
|
||||||
|
private boolean cheesable = true;
|
||||||
|
|
||||||
private static final GameProfile FAKE_PROFILE = new GameProfile(UUID.fromString("839eb18c-50bc-400c-8291-9383f09763e7"), "[NTM]");
|
private static final GameProfile FAKE_PROFILE = new GameProfile(UUID.fromString("839eb18c-50bc-400c-8291-9383f09763e7"), "[NTM]");
|
||||||
private static FakePlayer fakePlayer;
|
private static FakePlayer fakePlayer;
|
||||||
|
|
||||||
@ -280,6 +298,11 @@ public class BlockWandLoot extends BlockContainer implements ILookOverlay, ITool
|
|||||||
worldObj.setTileEntity(xCoord, yCoord, zCoord, te);
|
worldObj.setTileEntity(xCoord, yCoord, zCoord, te);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(te instanceof TileEntityLockableBase && lockCode != 0){
|
||||||
|
((TileEntityLockableBase) te).setPins(lockCode);
|
||||||
|
((TileEntityLockableBase) te).setMod(lockMod);
|
||||||
|
((TileEntityLockableBase) te).cheesable = lockMod != 0;
|
||||||
|
}
|
||||||
if(te instanceof IInventory) {
|
if(te instanceof IInventory) {
|
||||||
int count = minItems;
|
int count = minItems;
|
||||||
if(maxItems - minItems > 0) count += worldObj.rand.nextInt(maxItems - minItems);
|
if(maxItems - minItems > 0) count += worldObj.rand.nextInt(maxItems - minItems);
|
||||||
@ -332,6 +355,10 @@ public class BlockWandLoot extends BlockContainer implements ILookOverlay, ITool
|
|||||||
nbt.setString("pool", poolName);
|
nbt.setString("pool", poolName);
|
||||||
nbt.setFloat("rot", placedRotation);
|
nbt.setFloat("rot", placedRotation);
|
||||||
|
|
||||||
|
nbt.setInteger("lockCode", lockCode);
|
||||||
|
nbt.setFloat("lockMod", lockMod);
|
||||||
|
nbt.setBoolean("cheesable", cheesable);
|
||||||
|
|
||||||
nbt.setBoolean("trigger", triggerReplace);
|
nbt.setBoolean("trigger", triggerReplace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,6 +374,10 @@ public class BlockWandLoot extends BlockContainer implements ILookOverlay, ITool
|
|||||||
|
|
||||||
if(replaceBlock == null) replaceBlock = ModBlocks.deco_loot;
|
if(replaceBlock == null) replaceBlock = ModBlocks.deco_loot;
|
||||||
|
|
||||||
|
lockCode = nbt.getInteger("lockCode");
|
||||||
|
lockMod = nbt.getFloat("lockMod");
|
||||||
|
cheesable = nbt.getBoolean("cheesable");
|
||||||
|
|
||||||
triggerReplace = nbt.getBoolean("trigger");
|
triggerReplace = nbt.getBoolean("trigger");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,6 +388,11 @@ public class BlockWandLoot extends BlockContainer implements ILookOverlay, ITool
|
|||||||
buf.writeInt(minItems);
|
buf.writeInt(minItems);
|
||||||
buf.writeInt(maxItems);
|
buf.writeInt(maxItems);
|
||||||
BufferUtil.writeString(buf, poolName);
|
BufferUtil.writeString(buf, poolName);
|
||||||
|
|
||||||
|
buf.writeInt(lockCode);
|
||||||
|
buf.writeFloat(lockMod);
|
||||||
|
buf.writeBoolean(cheesable);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -366,6 +402,10 @@ public class BlockWandLoot extends BlockContainer implements ILookOverlay, ITool
|
|||||||
minItems = buf.readInt();
|
minItems = buf.readInt();
|
||||||
maxItems = buf.readInt();
|
maxItems = buf.readInt();
|
||||||
poolName = BufferUtil.readString(buf);
|
poolName = BufferUtil.readString(buf);
|
||||||
|
|
||||||
|
lockCode = buf.readInt();
|
||||||
|
lockMod = buf.readFloat();
|
||||||
|
cheesable = buf.readBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -379,6 +419,10 @@ public class BlockWandLoot extends BlockContainer implements ILookOverlay, ITool
|
|||||||
nbt.setInteger("maxItems", maxItems);
|
nbt.setInteger("maxItems", maxItems);
|
||||||
nbt.setString("poolName", poolName);
|
nbt.setString("poolName", poolName);
|
||||||
|
|
||||||
|
nbt.setInteger("lockCode", lockCode);
|
||||||
|
nbt.setFloat("lockMod", lockMod);
|
||||||
|
nbt.setBoolean("cheesable", cheesable);
|
||||||
|
|
||||||
return nbt;
|
return nbt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,6 +434,10 @@ public class BlockWandLoot extends BlockContainer implements ILookOverlay, ITool
|
|||||||
maxItems = nbt.getInteger("maxItems");
|
maxItems = nbt.getInteger("maxItems");
|
||||||
poolName = nbt.getString("poolName");
|
poolName = nbt.getString("poolName");
|
||||||
|
|
||||||
|
lockCode = nbt.getInteger("lockCode");
|
||||||
|
lockMod = nbt.getFloat("lockMod");
|
||||||
|
cheesable = nbt.getBoolean("cheesable");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,36 +9,43 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.ChatComponentText;
|
||||||
|
import net.minecraft.util.EnumChatFormatting;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class ItemCounterfeitKeys extends Item {
|
public class ItemCounterfeitKeys extends Item {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int b, float f0, float f1, float f2) {
|
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int b, float f0, float f1, float f2) {
|
||||||
TileEntity te = world.getTileEntity(x, y, z);
|
TileEntity te = world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
if(te instanceof TileEntityLockableBase) {
|
if(te instanceof TileEntityLockableBase) {
|
||||||
|
|
||||||
TileEntityLockableBase locked = (TileEntityLockableBase) te;
|
TileEntityLockableBase locked = (TileEntityLockableBase) te;
|
||||||
|
|
||||||
if(locked.isLocked()) {
|
if(locked.isLocked() && locked.cheesable) {
|
||||||
ItemStack st = new ItemStack(ModItems.key_fake);
|
ItemStack st = new ItemStack(ModItems.key_fake);
|
||||||
ItemKeyPin.setPins(st, locked.getPins());
|
ItemKeyPin.setPins(st, locked.getPins());
|
||||||
|
|
||||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, st.copy());
|
player.inventory.setInventorySlotContents(player.inventory.currentItem, st.copy());
|
||||||
|
|
||||||
if(!player.inventory.addItemStackToInventory(st.copy())) {
|
if(!player.inventory.addItemStackToInventory(st.copy())) {
|
||||||
player.dropPlayerItemWithRandomChoice(st.copy(), false);
|
player.dropPlayerItemWithRandomChoice(st.copy(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
player.inventoryContainer.detectAndSendChanges();
|
player.inventoryContainer.detectAndSendChanges();
|
||||||
|
|
||||||
player.swingItem();
|
player.swingItem();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
} else if(!locked.cheesable){
|
||||||
|
player.addChatMessage(new ChatComponentText(
|
||||||
|
EnumChatFormatting.LIGHT_PURPLE + "This lock is too elaborate for a counterfeit key to be made"));
|
||||||
|
player.addChatMessage(new ChatComponentText(
|
||||||
|
EnumChatFormatting.LIGHT_PURPLE + "Perhaps there is another way around here to unlock it"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,8 @@ public abstract class TileEntityLockableBase extends TileEntityLoadedBase {
|
|||||||
protected int lock;
|
protected int lock;
|
||||||
private boolean isLocked = false;
|
private boolean isLocked = false;
|
||||||
protected double lockMod = 0.1D;
|
protected double lockMod = 0.1D;
|
||||||
|
/** Whether a counterfeit lock can be made out of it*/
|
||||||
|
public boolean cheesable = true;
|
||||||
public boolean isLocked() {
|
public boolean isLocked() {
|
||||||
return isLocked;
|
return isLocked;
|
||||||
}
|
}
|
||||||
@ -44,6 +45,7 @@ public abstract class TileEntityLockableBase extends TileEntityLoadedBase {
|
|||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
lock = nbt.getInteger("lock");
|
lock = nbt.getInteger("lock");
|
||||||
|
cheesable = nbt.getBoolean("cheesable");
|
||||||
isLocked = nbt.getBoolean("isLocked");
|
isLocked = nbt.getBoolean("isLocked");
|
||||||
lockMod = nbt.getDouble("lockMod");
|
lockMod = nbt.getDouble("lockMod");
|
||||||
}
|
}
|
||||||
@ -53,6 +55,7 @@ public abstract class TileEntityLockableBase extends TileEntityLoadedBase {
|
|||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
nbt.setInteger("lock", lock);
|
nbt.setInteger("lock", lock);
|
||||||
|
nbt.setBoolean("cheesable", cheesable);
|
||||||
nbt.setBoolean("isLocked", isLocked);
|
nbt.setBoolean("isLocked", isLocked);
|
||||||
nbt.setDouble("lockMod", lockMod);
|
nbt.setDouble("lockMod", lockMod);
|
||||||
}
|
}
|
||||||
@ -62,6 +65,7 @@ public abstract class TileEntityLockableBase extends TileEntityLoadedBase {
|
|||||||
super.serialize(buf);
|
super.serialize(buf);
|
||||||
|
|
||||||
buf.writeInt(lock);
|
buf.writeInt(lock);
|
||||||
|
buf.writeBoolean(cheesable);
|
||||||
buf.writeBoolean(isLocked);
|
buf.writeBoolean(isLocked);
|
||||||
buf.writeDouble(lockMod);
|
buf.writeDouble(lockMod);
|
||||||
}
|
}
|
||||||
@ -71,6 +75,7 @@ public abstract class TileEntityLockableBase extends TileEntityLoadedBase {
|
|||||||
super.deserialize(buf);
|
super.deserialize(buf);
|
||||||
|
|
||||||
lock = buf.readInt();
|
lock = buf.readInt();
|
||||||
|
cheesable = buf.readBoolean();
|
||||||
isLocked = buf.readBoolean();
|
isLocked = buf.readBoolean();
|
||||||
lockMod = buf.readDouble();
|
lockMod = buf.readDouble();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user