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);
}
}
}
}
}
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;
}
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;
}
Aggregations