use of net.minecraft.world.ILockableContainer in project Skree by Skelril.
the class GoldRushListener method onChestClose.
@Listener
public void onChestClose(InteractInventoryEvent.Close event) {
Inventory inventory = event.getTargetInventory();
if (inventory instanceof ContainerChest) {
IInventory chestInv = ((ContainerChest) inventory).getLowerChestInventory();
if (chestInv instanceof ILockableContainer) {
String lockCode = ((ILockableContainer) chestInv).getLockCode().getLock();
Optional<Player> optPlayer = Optional.ofNullable(tileEntityClaimMap.remove(lockCode));
if (optPlayer.isPresent()) {
Player player = optPlayer.get();
((ILockableContainer) chestInv).setLockCode(LockCode.EMPTY_CODE);
Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent())
return;
// TODO Sponge port
GoldRushInstance inst = optInst.get();
List<org.spongepowered.api.item.inventory.ItemStack> toEvaluate = new ArrayList<>();
ArrayDeque<org.spongepowered.api.item.inventory.ItemStack> toReturn = new ArrayDeque<>();
for (int i = 0; i < chestInv.getSizeInventory(); ++i) {
ItemStack stack = chestInv.getStackInSlot(i);
if (stack == null) {
continue;
}
if (stack.getItem() instanceof CofferItem) {
toEvaluate.add(tf(stack));
} else {
toReturn.add(tf(stack));
}
chestInv.setInventorySlotContents(i, null);
}
BigDecimal value = BigDecimal.ZERO;
for (org.spongepowered.api.item.inventory.ItemStack stack : toEvaluate) {
value = value.add(new BigDecimal(CofferValueMap.inst().getValue(Collections.singleton(stack)).orElse(BigInteger.ZERO)));
}
inst.cofferRisk.put(player.getUniqueId(), value);
for (Inventory slot : player.getInventory().slots()) {
if (toReturn.isEmpty()) {
break;
}
if (slot.size() == 0) {
slot.set(toReturn.poll());
}
}
if (!toReturn.isEmpty()) {
new ItemDropper(player.getLocation()).dropStacks(toReturn, SpawnTypes.PLUGIN);
}
player.sendMessage(Text.of(TextColors.YELLOW, "You are now risking ", format(value), " coffers."));
MessageChannel targetChannel = inst.getPlayerMessageChannel(PlayerClassifier.SPECTATOR);
targetChannel.send(Text.of(TextColors.YELLOW, "Group risk of ", format(inst.getTotalRisk()), " coffers."));
targetChannel.send(Text.of(TextColors.YELLOW, "Risk of lava ", inst.getChanceOfLava(), " / 100."));
targetChannel.send(Text.of(TextColors.YELLOW, "Security system delay ", inst.getBaseTime(), " +/- ", inst.getTimeVariance(), " seconds."));
}
}
}
}
use of net.minecraft.world.ILockableContainer in project Bookshelf by Darkhax-Minecraft.
the class BlockBasicChest method getContainer.
@Override
public ILockableContainer getContainer(World world, BlockPos pos, boolean locked) {
final TileEntity tile = world.getTileEntity(pos);
if (!(tile instanceof TileEntityBasicChest)) {
return null;
} else {
ILockableContainer myChest = (TileEntityBasicChest) tile;
final IChestType myType = ((TileEntityBasicChest) tile).getType();
if (!locked && this.isBlocked(world, pos)) {
return null;
} else {
for (final EnumFacing facing : EnumFacing.Plane.HORIZONTAL) {
final BlockPos adjPos = pos.offset(facing);
final TileEntity adjTile = world.getTileEntity(adjPos);
if (world.getBlockState(adjPos).getBlock() == this && adjTile instanceof TileEntityBasicChest && ((TileEntityBasicChest) adjTile).getType() == myType) {
if (this.isBlocked(world, adjPos)) {
return null;
}
if (facing != EnumFacing.WEST && facing != EnumFacing.NORTH) {
myChest = new InventoryLargeChest("container.chestDouble", myChest, (TileEntityBasicChest) adjTile);
} else {
myChest = new InventoryLargeChest("container.chestDouble", (TileEntityBasicChest) adjTile, myChest);
}
}
}
return myChest;
}
}
}
use of net.minecraft.world.ILockableContainer in project MorePlanets by SteveKunG.
the class BlockInfectedChest method getLockableContainer.
@Override
public ILockableContainer getLockableContainer(World world, BlockPos pos) {
TileEntity tileentity = world.getTileEntity(pos);
if (!(tileentity instanceof TileEntityInfectedChest)) {
return null;
} else {
Object object = tileentity;
if (this.isBlocked(world, pos)) {
return null;
} else {
Iterator iterator = EnumFacing.Plane.HORIZONTAL.iterator();
while (iterator.hasNext()) {
EnumFacing enumfacing = (EnumFacing) iterator.next();
BlockPos blockpos1 = pos.offset(enumfacing);
Block block = world.getBlockState(blockpos1).getBlock();
if (block == this) {
if (this.isBlocked(world, blockpos1)) {
return null;
}
TileEntity tileentity1 = world.getTileEntity(blockpos1);
if (tileentity1 instanceof TileEntityInfectedChest) {
if (enumfacing != EnumFacing.WEST && enumfacing != EnumFacing.NORTH) {
object = new InventoryLargeChest(GCCoreUtil.translate("container.chestDouble"), (ILockableContainer) object, (TileEntityInfectedChest) tileentity1);
} else {
object = new InventoryLargeChest(GCCoreUtil.translate("container.chestDouble"), (TileEntityInfectedChest) tileentity1, (ILockableContainer) object);
}
}
}
}
return (ILockableContainer) object;
}
}
}
use of net.minecraft.world.ILockableContainer in project MorePlanets by SteveKunG.
the class BlockChestMP method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return true;
} else {
ILockableContainer ilockablecontainer = this.getLockableContainer(world, pos);
if (ilockablecontainer != null) {
player.displayGUIChest(ilockablecontainer);
player.addStat(StatList.CHEST_OPENED);
}
return true;
}
}
use of net.minecraft.world.ILockableContainer in project MorePlanets by SteveKunG.
the class BlockCheeseSporeChest method getLockableContainer.
@Override
public ILockableContainer getLockableContainer(World world, BlockPos pos) {
TileEntity tileentity = world.getTileEntity(pos);
if (!(tileentity instanceof TileEntityCheeseSporeChest)) {
return null;
} else {
Object object = tileentity;
if (this.isBlocked(world, pos)) {
return null;
} else {
Iterator iterator = EnumFacing.Plane.HORIZONTAL.iterator();
while (iterator.hasNext()) {
EnumFacing enumfacing = (EnumFacing) iterator.next();
BlockPos blockpos1 = pos.offset(enumfacing);
Block block = world.getBlockState(blockpos1).getBlock();
if (block == this) {
if (this.isBlocked(world, blockpos1)) {
return null;
}
TileEntity tileentity1 = world.getTileEntity(blockpos1);
if (tileentity1 instanceof TileEntityCheeseSporeChest) {
if (enumfacing != EnumFacing.WEST && enumfacing != EnumFacing.NORTH) {
object = new InventoryLargeChest(GCCoreUtil.translate("container.chestDouble"), (ILockableContainer) object, (TileEntityCheeseSporeChest) tileentity1);
} else {
object = new InventoryLargeChest(GCCoreUtil.translate("container.chestDouble"), (TileEntityCheeseSporeChest) tileentity1, (ILockableContainer) object);
}
}
}
}
return (ILockableContainer) object;
}
}
}
Aggregations