Jump to content

Rurido

Members
  • Posts

    23
  • Joined

  • Last visited

Everything posted by Rurido

  1. Is there a way to check if a dimension is already unloaded? (if the dimension should be deleted before it was loaded e.g. when no player joined the world yet) EDIT: nvm, I found a way: for(Integer i : DimensionManager.getIDs()){ if(id == i){ //Dimension is loaded. return false; //queued } } //Dimension is not loaded //continue
  2. I see... if(w == null || !ForgeChunkManager.getPersistentChunksFor(w).isEmpty() || !w.playerEntities.isEmpty() || dimension.type.shouldLoadSpawn()){ FMLLog.log.debug("Aborting unload for dimension {} as status changed", id); continue; } Well, i can teleport all players out of this dimension so that this list would be empty. I also found ForgeChunkManager.unloadWorld(World world) which removes its persistent chunks (forcedChunks.remove(world);) so that public static ImmutableSetMultimap<ChunkPos, Ticket> getPersistentChunksFor(World world){ return forcedChunks.containsKey(world) ? forcedChunks.get(world) : ImmutableSetMultimap.<ChunkPos,Ticket>of(); } would return an empty set. The spawn is not marked as "keep loaded" by my DimensionType. At last i would steal some code from DimensionManager.unloadWorlds(...); to get WorldServer w = worlds.get(id); MinecraftForge.EVENT_BUS.post(new WorldEvent.Unload(w)); w.flush(); setWorld(id, null, w.getMinecraftServer()); which should unload it immediately if i got things right. But isn't there a more elegant way or do I have to to all steps by myself?
  3. Do I have to use the event (I found WorldEvent.Unload) or can i force te dimension to unload immediately?
  4. I never wanted to remove a DimensionType. I want to remove a Dimension (by its id)!
  5. If the comment above the function is right, then you are wrong, idk... I give a DimensionType (which can also be identified by its id), and get a list of dimension ids... package net.minecraftforge.common; public class DimensionManager{ /*...*/ /** * Returns a list of dimensions associated with this DimensionType. */ public static int[] getDimensions(DimensionType type){ int[] ret = new int[dimensions.size()]; int x = 0; for (Map.Entry<Integer, Dimension> ent : dimensions.entrySet()){ if (ent.getValue().type == type){ ret[x++] = ent.getKey(); } } return Arrays.copyOf(ret, x); } /*...*/ }
  6. I don't know if my way creating dimensions is right, but I do use one DimensionType for multiple dimensions and all of them work fine: Screenshot: https://rurido.de/temp/mc_dim_list.png (Post was too long) [19:39:12] [Server thread/INFO] [RR55's Server+]: WorldInfo set on dimension 2 [19:39:12] [Server thread/INFO] [FML]: Loading dimension 2 (Test1) (net.minecraft.server.dedicated.DedicatedServer@2f011051) [19:39:15] [Server thread/INFO] [RR55's Server+]: WorldInfo set on dimension 3 [19:39:15] [Server thread/INFO] [FML]: Loading dimension 3 (Test2) (net.minecraft.server.dedicated.DedicatedServer@2f011051) [19:39:18] [Server thread/INFO] [RR55's Server+]: WorldInfo set on dimension 4 [19:39:18] [Server thread/INFO] [FML]: Loading dimension 4 (Test3) (net.minecraft.server.dedicated.DedicatedServer@2f011051) [19:39:20] [Server thread/INFO] [RR55's Server+]: WorldInfo set on dimension 5 [19:39:20] [Server thread/INFO] [FML]: Loading dimension 5 (Test4) (net.minecraft.server.dedicated.DedicatedServer@2f011051) So I would say that a DimensionType can be used for ore than one Dimension, because as I understand it, DimensionTypes don't say "what dimension are you?" but "what kind of dimension are you?". But I can also be wrong
  7. Please clarify what you mean by "this". I am talking about EnumHelper. And you? You said: Well, i never use the EnumHelper directly. It is used by DimensionType.register(...) but I don't want to remove (or add) DimensionTypes - I only do this once for all my custom dimensions which use all the same type: My code: public static DimensionType dimensionType; //<--- I could make it final, because it is only initialized once at FMLServerStartingEvent /*...*/ dimensionType = DimensionType.register("custom", "_custom", 5, CustomWorldProvider.class, false); Minecraft's source: net.minecraft.world.DimensionType: public static DimensionType register(String name, String suffix, int id, Class<? extends WorldProvider> provider, boolean keepLoaded){ String enum_name = name.replace(" ", "_").toLowerCase(); DimensionType ret = net.minecraftforge.common.util.EnumHelper.addEnum(DimensionType.class, enum_name, ENUM_ARGS, id, name, suffix, provider); return ret.setLoadSpawn(keepLoaded); } So as I said, i don't want to remove the entire type, I just want to remove some dimensions (all of my custom type tho). I really think we talk past each other
  8. If you call this a terrible hack, okay... And there is not "another terrible hack" to remove them?
  9. Adding them works just fine, no errors, nothing. My approach: So i thought removing them would be also that easy. Well if it CAN NOT be done, the server crash is "not a bug" but "a feature"...
  10. I try to remove dimensions (custom, not -1/0/1). After it was successfully removed, the server crashes. I think I forgot one thing but I can't figure out what. This is the remove-code: /*some imports*/ import net.minecraftforge.common.DimensionManager; import /*my package*/.util.LogHelper; public class Dimensions { /*some stuff*/ public static boolean removeDimension(int id) { if(!DimensionManager.isDimensionRegistered(id)) return false; try { LogHelper.info("Unloading dimension " + id); DimensionManager.unloadWorld(id); }catch (Exception ex){ LogHelper.warn(ex.getMessage()); } try { LogHelper.info("Unregistering dimension " + id); DimensionManager.unregisterDimension(id); }catch (Exception ex){ LogHelper.error(ex.getMessage()); return false; } LogHelper.info("Removing dimension " + id + " from data storage"); if( !DimensionDataStorage.removeDimension(id) ){ //<---DimensionDataStorage extends WorldSavedData LogHelper.warn("Could not delete data from DimensionDataStorage. This occurs if no data was found."); return false; } LogHelper.info("Dimension " + id + " successfully removed"); return true; } Crash Log after calling removeDimension(id[=3]): It looks like the dimension still exists after removing it; but when I restart the server it is gone exept that if I create a new dimension it's id is the id of the removed dimension +1, that's why the id is 3 and not 2 . Also the DIM[ID] folder is not beeing deleted. Any Idea what I forgot to add [or rather remove ^^]?
  11. You could use EntityJoinWorldEvent but this will also fire if for example the player re-enters a chunk where ItemFrames already were created. Nevertheless you can check what item is in there and then decide what to do.
  12. Can you please post your code to find the error? Some argument or variable seems to be null or a function returns null.
  13. Hi. I made a command to create new dimensions and I get some weitd bugs. Most of them are not relevant - the only thing that is "visible" for players is the following: If it starts to rain (no matter what dimension) and while it rains the player changes the dimension there is "rains" in the target dimension too. Also, if it doesn't rain but it rains in the target dimension, it also doesn't update the weather. I wonder if there is a SPacketSomething I can manually send to the player via ((EntityPlayerMp)player).connection.sendPacket(...); I found one for time (SPacketTimeUpdate) but none for weather. Is there another packet which sends the weather or can I do that somehow else? Everything has to happen @ Side.SERVER If a mistake is already in the teleportation - here is the code: public class CommandWorld extends CommandBase{ /*Command Stuff*/ @Override public void execute(...) throws CommandException { /*Argument stuff,...*/ WorldServer targetWorld = server.getWorld(target); server.getPlayerList().transferPlayerToDimension(player, target, new CustomTeleporter(targetWorld)); BlockPos targetSpawn = targetWorld.getTopSolidOrLiquidBlock(targetWorld.getSpawnPoint()); player.connection.setPlayerLocation(targetSpawn.getX(), targetSpawn.getY(), targetSpawn.getZ(), player.rotationYaw, player.rotationPitch); } } And as always - thanks in advance! EDIT: I found a kind of workaround.
  14. Well... idk what to write in my own feed... probably something like... idk...

    true is that:                  null != 0  null !<0   null  !> 0  

    but also this is true:  null <= 0  null >= 0  Number(null) == 0

    JavaScript is kinda fun xD

  15. Good to know, but that was nothing I wanted to do. Like my little piece of code showed I simply added some placement rules for seeds in dispensers. But anyways, thank you! PS: Do threads get closed here? I think this would be the right point to do so ^^
  16. As far as I know, my behaviors use items with no behavior in (vanilla) Minecraft, so no, I don't remove any behaviors. Should I remove a behavior provisionally before I add it to make sure it is compatible with other mods?
  17. Thanks for the advice. It works now! Just to be sure, is everything as it should be? @Mod(modid = Main.MODID, version = Main.VERSION) public class Main { /*init stuff*/ @EventHandler public static void postInit(FMLPostInitializationEvent event){ RecipeManager.initDispenserBehavior(); } } public class RecipeManager { /*some stuff*/ public void initDispenserBehavior(){ BlockDispenser.DISPENSE_BEHAVIOR_REGISTRY.putObject(Items.WHEAT_SEEDS, new BehaviorPlaceBlock(Blocks.WHEAT, 1, 4)); /*more stuff*/ } } public class BehaviorPlaceBlock implements IBehaviorDispenseItem { protected final IBlockState iBlockState; protected int offset = 1; protected int maxRange = 1; public BehaviorPlaceBlock(Block blockToPlace, int offset, int maxRange){ iBlockState = blockToPlace.getDefaultState(); this.offset = offset; this.maxRange = maxRange; } @Override public ItemStack dispense(IBlockSource source, ItemStack stack) { /*do some stuff*/ } }
  18. Hi. I searched for an event that is triggered when a dispenser throws an item. I got the following, but it is not quite what I wanted, because here I can't prevent the item from being dispensed: @Mod.EventBusSubscriber public class EventHandler { /*some stuff*/ @SubscribeEvent public static void onBlock(BlockEvent ev) { World world = ev.getWorld(); BlockPos blockPos = ev.getPos(); IBlockState iBlockState = world.getBlockState(blockPos); if(iBlockState.getBlock() instanceof BlockDispenser){ if(iBlockState.getValue(BlockDispenser.TRIGGERED)){ ChatHelper.sendChatMsgToAllPlayers(ev.getWorld().getMinecraftServer(), "Dispenser fired!"); /*prevent drop | hook own routine*/ } } } } Any Idea how to stop the item from being dropped / which event to use instead? This all has to happen @ server side... Thanks in advance, Rurido.
  19. Works fine! Updated code: public static final ImmutableSet<Block> usableBlocks = ImmutableSet.of(Blocks.CHEST, Blocks.ENDER_CHEST, Blocks.TRAPPED_CHEST, Blocks.OAK_DOOR, Blocks.ACACIA_DOOR, Blocks.BIRCH_DOOR, Blocks.DARK_OAK_DOOR, Blocks.JUNGLE_DOOR, Blocks.SPRUCE_DOOR, Blocks.TRAPDOOR, Blocks.ACACIA_FENCE_GATE, Blocks.BIRCH_FENCE_GATE, Blocks.DARK_OAK_FENCE_GATE, Blocks.JUNGLE_FENCE_GATE, Blocks.OAK_FENCE_GATE, Blocks.SPRUCE_FENCE_GATE, Blocks.POWERED_REPEATER, Blocks.UNPOWERED_REPEATER, Blocks.POWERED_COMPARATOR, Blocks.UNPOWERED_COMPARATOR, Blocks.STONE_BUTTON, Blocks.WOODEN_BUTTON, Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.LEVER, Blocks.DAYLIGHT_DETECTOR, Blocks.DAYLIGHT_DETECTOR_INVERTED, Blocks.DROPPER, Blocks.DISPENSER, Blocks.FURNACE, Blocks.LIT_FURNACE, Blocks.ENCHANTING_TABLE, Blocks.HOPPER, Blocks.ANVIL, Blocks.BED, Blocks.BLACK_SHULKER_BOX, Blocks.BLUE_SHULKER_BOX, Blocks.BROWN_SHULKER_BOX, Blocks.CYAN_SHULKER_BOX, Blocks.GRAY_SHULKER_BOX, Blocks.GREEN_SHULKER_BOX, Blocks.LIGHT_BLUE_SHULKER_BOX, Blocks.LIME_SHULKER_BOX, Blocks.MAGENTA_SHULKER_BOX, Blocks.ORANGE_SHULKER_BOX, Blocks.PINK_SHULKER_BOX, Blocks.PURPLE_SHULKER_BOX, Blocks.RED_SHULKER_BOX, Blocks.SILVER_SHULKER_BOX, Blocks.WHITE_SHULKER_BOX, Blocks.YELLOW_SHULKER_BOX, Blocks.BREWING_STAND, Blocks.CRAFTING_TABLE); public static boolean isBlockUsableByPlayer(Block block){ return usableBlocks.contains(block); } public static boolean isBlockUsableByPlayer(IBlockState iBlockState){ return isBlockUsableByPlayer(iBlockState.getBlock()); }
  20. I applied my idea and it seems to work. I made the following changes: @Mod.EventBusSubscriber public class EventHandler { /*some stuff*/ @SubscribeEvent public static void onPlayerRightClickBlock(PlayerInteractEvent.RightClickBlock ev){ /*previous return blocks*/ if(BlockUtil.isBlockUsableByPlayer(iBlockState)) return; //Filter right-clickable blocks /*spawn block*/ } } public final class BlockUtil { public static final List<Block> usableBlocks = Arrays.asList(new Block[]{Blocks.CHEST, Blocks.ENDER_CHEST, Blocks.TRAPPED_CHEST, Blocks.OAK_DOOR, Blocks.ACACIA_DOOR, Blocks.BIRCH_DOOR, Blocks.DARK_OAK_DOOR, Blocks.JUNGLE_DOOR, Blocks.SPRUCE_DOOR, Blocks.TRAPDOOR, Blocks.ACACIA_FENCE_GATE, Blocks.BIRCH_FENCE_GATE, Blocks.DARK_OAK_FENCE_GATE, Blocks.JUNGLE_FENCE_GATE, Blocks.OAK_FENCE_GATE, Blocks.SPRUCE_FENCE_GATE, Blocks.POWERED_REPEATER, Blocks.UNPOWERED_REPEATER, Blocks.POWERED_COMPARATOR, Blocks.UNPOWERED_COMPARATOR, Blocks.STONE_BUTTON, Blocks.WOODEN_BUTTON, Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.LEVER, Blocks.DAYLIGHT_DETECTOR, Blocks.DAYLIGHT_DETECTOR_INVERTED, Blocks.DROPPER, Blocks.DISPENSER, Blocks.FURNACE, Blocks.LIT_FURNACE, Blocks.ENCHANTING_TABLE, Blocks.HOPPER, Blocks.ANVIL, Blocks.BED, Blocks.BLACK_SHULKER_BOX, Blocks.BLUE_SHULKER_BOX, Blocks.BROWN_SHULKER_BOX, Blocks.CYAN_SHULKER_BOX, Blocks.GRAY_SHULKER_BOX, Blocks.GREEN_SHULKER_BOX, Blocks.LIGHT_BLUE_SHULKER_BOX, Blocks.LIME_SHULKER_BOX, Blocks.MAGENTA_SHULKER_BOX, Blocks.ORANGE_SHULKER_BOX, Blocks.PINK_SHULKER_BOX, Blocks.PURPLE_SHULKER_BOX, Blocks.RED_SHULKER_BOX, Blocks.SILVER_SHULKER_BOX, Blocks.WHITE_SHULKER_BOX, Blocks.YELLOW_SHULKER_BOX, Blocks.BREWING_STAND, Blocks.CRAFTING_TABLE}); public static boolean isBlockUsableByPlayer(Block block){ return usableBlocks.contains(block); } public static boolean isBlockUsableByPlayer(IBlockState iBlockState){ return isBlockUsableByPlayer(iBlockState.getBlock()); } /*some other stuff*/ } DONE Should I do .sort() once or is there a way I can define it already sorted manually? All Usable Blocks i found, did I miss one?
  21. The big problem is, that i can't create my own items without creating a client version of the mod, right? So that onItemUse(...){...} is not an option. My last idea was - a rather ugly solution, but hey, it's one - to check manually if a block could handle the click action and decide if i have to spawn the item or not, like this: /*previous return blocks*/ List<Block> usableBlocks = Arrays.asList(new Block[]{Blocks.CHEST, Blocks.ENDER_CHEST, Blocks.OAK_DOOR /*and so on...*/}); if(usableBlocks.contains(iBlockState.getBlock())) return; /*spawn block*/ But i don't think this would do well when it comes to performance... Opinion(s)?
  22. Hi. I'm trying to catch the RightClickBlock Event. Everything works fine, but what I didn't expect was that it also triggers if the player opens a chest; but I need it to only trigger if the block can't be used (so not Chests, Doors, Buttons...) To be more detailed: I want to spawn an ItemMonsterPlacer (no NBT) whenever a player uses a ItemMonsterPlacer (with NBT) and an entity is spawned. Another note: Everything has to be Server-Sided, because it's a Server-Only mod. This is what I have: @SubscribeEvent public static void onPlayerRightClickBlock(PlayerInteractEvent.RightClickBlock ev){ World world = ev.getWorld(); EntityPlayer entityPlayer = ev.getEntityPlayer(); ItemStack itemStack = ev.getItemStack(); BlockPos blockPos = ev.getPos(); IBlockState iBlockState = world.getBlockState(blockPos); EnumFacing enumFacing = ev.getFace(); if(itemStack.getItem() instanceof ItemMonsterPlacer){ if(itemStack.getTagCompound() == null) return; //Filter Capture Items if(!entityPlayer.canPlayerEdit(blockPos.offset(enumFacing), enumFacing, itemStack)) return; //Filter if player edit, not use; see ItemMonsterPlacer if(world.getBlockState(blockPos).getBlock() == Blocks.MOB_SPAWNER) return; //Filter MOB_SPAWNER Blocks if(entityPlayer.capabilities.isCreativeMode) return; //Filter creative mode. entityPlayer.sendMessage(new TextComponentString("" + world.)); world.spawnEntity(new EntityItem(world, blockPos.getX(), blockPos.getY()+2, blockPos.getZ(), new ItemStack(Items.SPAWN_EGG))); if(entityPlayer instanceof EntityPlayerMP) ((EntityPlayerMP)entityPlayer).connection.sendPacket(new SPacketCustomSound("minecraft:entity.endermen.teleport", SoundCategory.AMBIENT, blockPos.getX(), blockPos.getY(), blockPos.getZ(), (float)1, (float)1)); return; } Many thanks in advance Rurido
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.