use of com.mrcrayfish.furniture.tileentity.TileEntityComputer in project MrCrayfishFurnitureMod by MrCrayfish.
the class BlockComputer method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
TileEntity tile_entity = worldIn.getTileEntity(pos);
if (tile_entity instanceof TileEntityComputer) {
TileEntityComputer computer = (TileEntityComputer) tile_entity;
if (!computer.isTrading()) {
computer.setTrading(true);
playerIn.openGui(MrCrayfishFurnitureMod.instance, 0, worldIn, pos.getX(), pos.getY(), pos.getZ());
} else {
if (!worldIn.isRemote) {
playerIn.sendMessage(new TextComponentTranslation("cfm.message.computer"));
}
}
}
return true;
}
use of com.mrcrayfish.furniture.tileentity.TileEntityComputer in project MrCrayfishFurnitureMod by MrCrayfish.
the class MessageMineBayClosed method onMessage.
@Override
public IMessage onMessage(MessageMineBayClosed message, MessageContext ctx) {
final WorldServer world = ctx.getServerHandler().player.getServerWorld();
world.addScheduledTask(() -> {
EntityPlayerMP player = ctx.getServerHandler().player;
TileEntity tile_entity = world.getTileEntity(new BlockPos(message.x, message.y, message.z));
if (tile_entity instanceof TileEntityComputer) {
TileEntityComputer tileEntityComputer = (TileEntityComputer) tile_entity;
if (!tileEntityComputer.getStackInSlot(0).isEmpty()) {
player.world.spawnEntity(new EntityItem(world, player.posX, player.posY, player.posZ, tileEntityComputer.getStackInSlot(0)));
tileEntityComputer.setInventorySlotContents(0, ItemStack.EMPTY);
}
tileEntityComputer.setTrading(false);
BlockPos pos = new BlockPos(message.x, message.y, message.z);
TileEntityUtil.markBlockForUpdate(world, pos);
}
});
return null;
}
use of com.mrcrayfish.furniture.tileentity.TileEntityComputer in project MrCrayfishFurnitureMod by MrCrayfish.
the class MessageMineBayBrowse method onMessage.
@Override
public IMessage onMessage(MessageMineBayBrowse message, MessageContext ctx) {
final WorldServer world = ctx.getServerHandler().player.getServerWorld();
world.addScheduledTask(() -> {
EntityPlayerMP player = ctx.getServerHandler().player;
TileEntity tile_entity = player.world.getTileEntity(new BlockPos(message.x, message.y, message.z));
if (tile_entity instanceof TileEntityComputer) {
TileEntityComputer tileEntityComputer = (TileEntityComputer) tile_entity;
tileEntityComputer.setBrowsingInfo(message.itemNum);
BlockPos pos = new BlockPos(message.x, message.y, message.z);
TileEntityUtil.markBlockForUpdate(ctx.getServerHandler().player.world, pos);
}
});
return null;
}
use of com.mrcrayfish.furniture.tileentity.TileEntityComputer in project MrCrayfishFurnitureMod by MrCrayfish.
the class MessageMineBayBuy method onMessage.
@Override
public IMessage onMessage(MessageMineBayBuy message, MessageContext ctx) {
final WorldServer world = ctx.getServerHandler().player.getServerWorld();
world.addScheduledTask(() -> {
EntityPlayer player = ctx.getServerHandler().player;
TileEntity tileEntity = player.world.getTileEntity(new BlockPos(message.x, message.y, message.z));
if (tileEntity instanceof TileEntityComputer) {
TileEntityComputer tileEntityComputer = (TileEntityComputer) tileEntity;
ItemStack buySlot = tileEntityComputer.getStackInSlot(0);
if (buySlot.isEmpty())
return;
RecipeData[] data = Recipes.getMineBayItems();
if (message.itemNum < 0 || message.itemNum >= data.length)
return;
RecipeData recipe = data[message.itemNum];
int price = recipe.getPrice();
if (recipe.getCurrency().getItem() == buySlot.getItem() && buySlot.getCount() >= price) {
tileEntityComputer.takeEmeraldFromSlot(price);
EntityItem entityItem = new EntityItem(player.world, player.posX, player.posY + 1, player.posZ, data[message.itemNum].getInput().copy());
player.world.spawnEntity(entityItem);
Triggers.trigger(Triggers.MINEBAY_PURCHASE, player);
}
}
});
return null;
}
Aggregations