use of lumien.randomthings.handler.floo.FlooNetworkHandler in project Random-Things by lumien231.
the class RTCommand method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length == 0) {
return;
}
if (args[0].equals("setBiomeCrystal")) {
if (args.length == 2 && sender instanceof EntityPlayer) {
String biomeName = args[1];
EntityPlayer player = (EntityPlayer) sender;
ItemStack equipped = player.getHeldItemMainhand();
if (equipped != null && equipped.getItem() instanceof ItemBiomeCrystal) {
if (equipped.getTagCompound() == null) {
equipped.setTagCompound(new NBTTagCompound());
}
equipped.getTagCompound().setString("biomeName", args[1]);
}
}
} else if (args[0].equals("generateBiomeCrystalChests")) {
if (sender instanceof EntityPlayer) {
List<ResourceLocation> biomeIds = new ArrayList<>(Biome.REGISTRY.getKeys());
int modX = 0;
while (!biomeIds.isEmpty()) {
sender.getEntityWorld().setBlockState(sender.getPosition().add(modX, 0, 0), Blocks.CHEST.getDefaultState());
IInventory inventory = (IInventory) sender.getEntityWorld().getTileEntity(sender.getPosition().add(modX, 0, 0));
for (int i = 0; i < 27; i++) {
if (!biomeIds.isEmpty()) {
ResourceLocation next = biomeIds.remove(biomeIds.size() - 1);
ItemStack crystal = new ItemStack(ModItems.biomeCrystal);
crystal.setTagCompound(new NBTTagCompound());
crystal.getTagCompound().setString("biomeName", next.toString());
inventory.setInventorySlotContents(i, crystal);
}
}
modX += 2;
}
}
} else if (args[0].equals("tpFilter")) {
if (sender instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) sender;
ItemStack held;
if ((held = player.getHeldItemMainhand()) != null && held.getItem() == ModItems.positionFilter) {
BlockPos pos = ItemPositionFilter.getPosition(held);
player.connection.setPlayerLocation(pos.getX(), pos.getY() + 150, pos.getZ(), player.rotationYaw, player.rotationPitch);
}
}
} else if (args[0].equals("testSlimeSpawn")) {
BlockPos pos = sender.getPosition();
World world = sender.getEntityWorld();
if (pos != null && world != null) {
EntitySlime slime = new EntitySlime(world);
slime.setLocationAndAngles(pos.getX(), pos.getY(), pos.getZ(), 0F, 0F);
sender.sendMessage(new TextComponentString(slime.getCanSpawnHere() + ""));
}
} else if (args[0].equals("notify") && args.length == 5) {
String title = args[1];
String body = args[2];
String itemName = args[3];
String player = args[4];
EntityPlayerMP playerEntity = server.getPlayerList().getPlayerByUsername(player);
ItemStack itemStack = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemName)));
MessageNotification message = new MessageNotification(title, body, itemStack);
PacketHandler.INSTANCE.sendTo(message, playerEntity);
} else if (args[0].equals("fireplaces")) {
FlooNetworkHandler handler = FlooNetworkHandler.get(sender.getEntityWorld());
List<FlooFireplace> firePlaces = handler.getFirePlaces();
sender.sendMessage(new TextComponentString("Floo Fireplaces in Dimension " + sender.getEntityWorld().provider.getDimension()).setStyle(new Style().setUnderlined(true)));
sender.sendMessage(new TextComponentString(""));
for (FlooFireplace firePlace : firePlaces) {
String name = firePlace.getName();
UUID creator = firePlace.getCreatorUUID();
String ownerName = null;
if (creator != null) {
GameProfile profile = server.getPlayerProfileCache().getProfileByUUID(creator);
if (profile != null) {
ownerName = profile.getName();
}
}
BlockPos pos = firePlace.getLastKnownPosition();
sender.sendMessage(new TextComponentString((name == null ? "<Unnamed>" : name) + " | " + String.format("%d %d %d", pos.getX(), pos.getY(), pos.getZ()) + (ownerName != null ? " | " + ownerName : "")));
}
} else if (args[0].equals("festival")) {
FestivalHandler handler = FestivalHandler.get(sender.getEntityWorld());
List<EntityVillager> villagerList = sender.getEntityWorld().getEntitiesWithinAABB(EntityVillager.class, new AxisAlignedBB(sender.getPosition()).grow(50));
if (!villagerList.isEmpty()) {
EntityVillager villager = villagerList.get(0);
int success = handler.addFestival(villager);
if (success == 2) {
sender.sendMessage(new TextComponentTranslation("command.festival.scheduled"));
} else {
sender.sendMessage(new TextComponentTranslation("command.festival.failed"));
}
} else {
sender.sendMessage(new TextComponentTranslation("command.festival.novillager"));
}
} else if (args[0].equals("ancientFurnace")) {
WorldGenAncientFurnace.pattern.place(sender.getEntityWorld(), sender.getPosition(), 3);
}
}
use of lumien.randomthings.handler.floo.FlooNetworkHandler 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.handler.floo.FlooNetworkHandler in project Random-Things by lumien231.
the class TileEntityFlooBrick method breakBlock.
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
if (!amMaster) {
if (masterUUID != null) {
FlooNetworkHandler handler = FlooNetworkHandler.get(worldIn);
TileEntity masterTE = handler.getFirePlaceTE(worldIn, masterUUID);
if (masterTE instanceof TileEntityFlooBrick) {
((TileEntityFlooBrick) masterTE).breakBlock(worldIn, masterTE.getPos(), state);
}
}
} else {
for (BlockPos children : children) {
worldIn.setBlockState(children, Blocks.BRICK_BLOCK.getDefaultState());
}
FlooNetworkHandler.get(worldIn).brokenMaster(worldIn, pos, this);
worldIn.setBlockState(this.pos, Blocks.BRICK_BLOCK.getDefaultState());
}
}
Aggregations