Search in sources :

Example 1 with TileEntityFlooBrick

use of lumien.randomthings.tileentity.TileEntityFlooBrick in project Random-Things by lumien231.

the class RTEventHandler method chatEvent.

@SubscribeEvent
public void chatEvent(ServerChatEvent event) {
    EntityPlayerMP player = event.getPlayer();
    BlockPos below = player.getPosition().down();
    IBlockState state = player.world.getBlockState(below);
    ItemStack flooDust = player.getHeldItemMainhand();
    if (!player.world.getEntitiesWithinAABB(EntityTemporaryFlooFireplace.class, player.getEntityBoundingBox().grow(0.5)).isEmpty()) {
        String target = event.getMessage();
        FlooNetworkHandler networkHandler = FlooNetworkHandler.get(player.world);
        boolean success = networkHandler.teleport(player.world, null, null, player, target);
        if (success) {
            event.setCanceled(true);
        }
    } else if ((player.capabilities.isCreativeMode || (!flooDust.isEmpty() && flooDust.getItem() instanceof ItemIngredient && flooDust.getItemDamage() == ItemIngredient.INGREDIENT.FLOO_POWDER.id)) && state.getBlock() == ModBlocks.flooBrick) {
        String target = event.getMessage();
        TileEntityFlooBrick te = (TileEntityFlooBrick) player.world.getTileEntity(below);
        UUID firePlaceUUID = te.getFirePlaceUid();
        if (firePlaceUUID != null) {
            FlooNetworkHandler networkHandler = FlooNetworkHandler.get(player.world);
            TileEntity masterTE = networkHandler.getFirePlaceTE(player.world, firePlaceUUID);
            if (masterTE instanceof TileEntityFlooBrick) {
                TileEntityFlooBrick masterBrick = ((TileEntityFlooBrick) masterTE);
                if (masterBrick.isMaster()) {
                    boolean success = networkHandler.teleport(player.world, masterBrick.getPos(), masterBrick, player, target);
                    if (success) {
                        if (!player.capabilities.isCreativeMode) {
                            flooDust.shrink(1);
                        }
                    }
                    event.setCanceled(true);
                }
            }
        }
        return;
    }
    if (!(player instanceof FakePlayer) && player.getGameProfile() != null) {
        Iterator<TileEntityChatDetector> iterator = TileEntityChatDetector.detectors.iterator();
        while (iterator.hasNext()) {
            TileEntityChatDetector chatDetector = iterator.next();
            if (chatDetector.isInvalid()) {
                iterator.remove();
            } else {
                if (chatDetector.checkMessage(event.getPlayer(), event.getMessage())) {
                    event.setCanceled(true);
                }
            }
        }
        Iterator<TileEntityGlobalChatDetector> iteratorGlobal = TileEntityGlobalChatDetector.detectors.iterator();
        while (iteratorGlobal.hasNext()) {
            TileEntityGlobalChatDetector chatDetector = iteratorGlobal.next();
            if (chatDetector.isInvalid()) {
                iteratorGlobal.remove();
            } else {
                if (chatDetector.checkMessage(event.getPlayer(), event.getMessage())) {
                    event.setCanceled(true);
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) TileEntityFlooBrick(lumien.randomthings.tileentity.TileEntityFlooBrick) TileEntityChatDetector(lumien.randomthings.tileentity.TileEntityChatDetector) FakePlayer(net.minecraftforge.common.util.FakePlayer) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityGlobalChatDetector(lumien.randomthings.tileentity.TileEntityGlobalChatDetector) FlooNetworkHandler(lumien.randomthings.handler.floo.FlooNetworkHandler) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) ItemIngredient(lumien.randomthings.item.ItemIngredient) UUID(java.util.UUID) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with TileEntityFlooBrick

use of lumien.randomthings.tileentity.TileEntityFlooBrick in project Random-Things by lumien231.

the class ItemFlooSign method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState state = worldIn.getBlockState(pos);
    if (state.getBlock() == Blocks.BRICK_BLOCK) {
        if (!worldIn.isRemote) {
            String signName = null;
            ItemStack flooSign = player.getHeldItem(hand);
            if (flooSign.hasTagCompound()) {
                NBTTagCompound compound = flooSign.getTagCompound();
                if (compound.hasKey("display")) {
                    NBTTagCompound displayCompound = compound.getCompoundTag("display");
                    if (displayCompound.hasKey("Name", 8)) {
                        signName = displayCompound.getString("Name");
                    }
                }
            }
            EnumFacing teleportFacing = facing;
            if (!teleportFacing.getAxis().isHorizontal()) {
                teleportFacing = player.getHorizontalFacing().getOpposite();
            }
            List<BlockPos> brickList = new ArrayList<BlockPos>();
            List<BlockPos> checkStack = new ArrayList<BlockPos>();
            checkStack.add(pos);
            HashSet<BlockPos> checkedPositions = new HashSet<BlockPos>();
            while (!checkStack.isEmpty()) {
                BlockPos take = checkStack.remove(checkStack.size() - 1);
                if (checkedPositions.contains(take)) {
                    continue;
                }
                checkedPositions.add(take);
                IBlockState takeState = worldIn.getBlockState(take);
                if (takeState.getBlock() == Blocks.BRICK_BLOCK) {
                    if (brickList.size() > 20) {
                        return EnumActionResult.FAIL;
                    }
                    brickList.add(take);
                    for (EnumFacing offSetFacing : EnumFacing.HORIZONTALS) {
                        BlockPos offPos = take.offset(offSetFacing);
                        checkStack.add(offPos);
                    }
                } else if (takeState.getBlock() == ModBlocks.flooBrick) {
                    return EnumActionResult.FAIL;
                }
            }
            brickList.remove(pos);
            UUID uuid = UUID.randomUUID();
            boolean valid = FlooNetworkHandler.get(worldIn).createFireplace(worldIn, uuid, signName, player, pos, brickList);
            if (valid) {
                worldIn.setBlockState(pos, ModBlocks.flooBrick.getDefaultState());
                TileEntityFlooBrick masterTE = (TileEntityFlooBrick) worldIn.getTileEntity(pos);
                masterTE.initToMaster(brickList, teleportFacing, uuid);
                for (BlockPos brickPos : brickList) {
                    worldIn.setBlockState(brickPos, ModBlocks.flooBrick.getDefaultState());
                    TileEntityFlooBrick te = (TileEntityFlooBrick) worldIn.getTileEntity(brickPos);
                    te.initToChild(uuid);
                }
                if (!player.capabilities.isCreativeMode) {
                    flooSign.shrink(1);
                }
            }
        }
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.PASS;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ArrayList(java.util.ArrayList) TileEntityFlooBrick(lumien.randomthings.tileentity.TileEntityFlooBrick) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 3 with TileEntityFlooBrick

use of lumien.randomthings.tileentity.TileEntityFlooBrick in project Random-Things by lumien231.

the class FlooNetworkHandler method teleport.

public boolean teleport(World world, BlockPos originPos, TileEntityFlooBrick originTE, EntityPlayerMP player, String enteredDestination) {
    FlooFireplace targetFirePlace = null;
    double closest = Double.MAX_VALUE;
    for (FlooFireplace firePlace : firePlaces) {
        String firePlaceName = firePlace.getName();
        if (firePlaceName != null) {
            double sim = stringSim.distance(firePlaceName, enteredDestination);
            if (sim < closest) {
                closest = sim;
                targetFirePlace = firePlace;
            }
        }
    }
    if (targetFirePlace != null) {
        if (originPos != null && targetFirePlace.lastKnownPosition.equals(originPos)) {
            player.sendMessage(new TextComponentTranslation("floo.info.same"));
            return false;
        } else {
            BlockPos targetPos = targetFirePlace.getLastKnownPosition();
            TileEntity te = world.getTileEntity(targetPos);
            if (te instanceof TileEntityFlooBrick) {
                TileEntityFlooBrick targetTE = (TileEntityFlooBrick) te;
                if (targetTE.isMaster()) {
                    EnumFacing tpFacing = targetTE.getFacing();
                    BlockPos teleportTarget = targetPos.up();
                    player.connection.setPlayerLocation(teleportTarget.getX() + 0.5, teleportTarget.getY(), teleportTarget.getZ() + 0.5, tpFacing.getHorizontalAngle(), 0);
                    player.sendMessage(new TextComponentTranslation("floo.info.teleport", targetFirePlace.getName()));
                    // Particles
                    if (originPos != null && originTE != null) {
                        List<BlockPos> originPositions = new ArrayList<BlockPos>();
                        originPositions.add(originPos);
                        originPositions.addAll(originTE.getChildren());
                        MessageFlooParticles p1 = new MessageFlooParticles(originPositions);
                        MessageUtil.sendToAllWatchingPos(player.world, originPos, p1);
                    }
                    List<BlockPos> destinationPositions = new ArrayList<BlockPos>();
                    destinationPositions.add(targetPos);
                    destinationPositions.addAll(targetTE.getChildren());
                    MessageFlooParticles p2 = new MessageFlooParticles(destinationPositions);
                    MessageUtil.sendToAllWatchingPos(player.world, targetPos, p2);
                    PacketHandler.INSTANCE.sendTo(p2, player);
                    return true;
                }
            }
            firePlaces.remove(targetFirePlace);
            this.markDirty();
            return teleport(world, originPos, originTE, player, enteredDestination);
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) MessageFlooParticles(lumien.randomthings.network.messages.MessageFlooParticles) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) TileEntityFlooBrick(lumien.randomthings.tileentity.TileEntityFlooBrick)

Aggregations

TileEntityFlooBrick (lumien.randomthings.tileentity.TileEntityFlooBrick)3 BlockPos (net.minecraft.util.math.BlockPos)3 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 IBlockState (net.minecraft.block.state.IBlockState)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 HashSet (java.util.HashSet)1 FlooNetworkHandler (lumien.randomthings.handler.floo.FlooNetworkHandler)1 ItemIngredient (lumien.randomthings.item.ItemIngredient)1 MessageFlooParticles (lumien.randomthings.network.messages.MessageFlooParticles)1 TileEntityChatDetector (lumien.randomthings.tileentity.TileEntityChatDetector)1 TileEntityGlobalChatDetector (lumien.randomthings.tileentity.TileEntityGlobalChatDetector)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 FakePlayer (net.minecraftforge.common.util.FakePlayer)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1