Jump to content

ptolemy2002

Members
  • Posts

    27
  • Joined

  • Last visited

Everything posted by ptolemy2002

  1. Which event should I be using to accomplish this? Currently I am trying to subscribe to the TagsUpdatedEvent, but it doesn't appear to be called at all. @Mod.EventBusSubscriber(bus=Bus.FORGE) public static class GenericEvents { @SubscribeEvent public static void onTagsUpdated(TagsUpdatedEvent event) { ... } }
  2. I'm trying to develop a simple mod that will export certain properties of every registered item to an external file. Most of my properties are working, but I'm having trouble trying to implement the burnTime property. First, I tried using item.getBurnTime(new ItemStack(item, 1)) and found that method was repeatedly returning "-1" because the value was to be determined by the vanilla Minecraft Logic. I then did some research and found that I could use this: ForgeHooks.getBurnTime(new ItemStack(item, 1)) I found that this was continuously returning "0" instead of my desired value, presumably because the map "VANILLA_BURNS" has no entry for the item. Finally, I tried using the deprecated FurnaceTileEntity.getBurnTimes().get(item) where I got the error java.lang.IllegalStateException: Tag minecraft:non_flammable_wood used before it was bound Stacktrace: at net.minecraft.tags.TagRegistry$NamedTag.getTag(TagRegistry.java:131) ~[forge-1.16.4-35.0.18_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.tags.TagRegistry$NamedTag.contains(TagRegistry.java:142) ~[forge-1.16.4-35.0.18_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.tileentity.AbstractFurnaceTileEntity.isNonFlammable(AbstractFurnaceTileEntity.java:161) ~[forge-1.16.4-35.0.18_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading} at net.minecraft.tileentity.AbstractFurnaceTileEntity.addItemBurnTime(AbstractFurnaceTileEntity.java:175) ~[forge-1.16.4-35.0.18_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading} at net.minecraft.tileentity.AbstractFurnaceTileEntity.getBurnTimes(AbstractFurnaceTileEntity.java:97) ~[forge-1.16.4-35.0.18_mapped_snapshot_20201028-1.16.3-recomp.jar:?] {re:classloading} at com.example.examplemod.ExampleMod.setup(ExampleMod.java:104) ~[main/:?] {re:classloading} at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:247) ~[eventbus-3.0.5-service.jar:?] {} at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:239) ~[eventbus-3.0.5-service.jar:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:297) ~[eventbus-3.0.5-service.jar:?] {} at net.minecraftforge.fml.javafmlmod.FMLModContainer.acceptEvent(FMLModContainer.java:120) ~[forge:?] {re:classloading} at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:121) ~[forge:?] {re:classloading} at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1800) ~[?:?] {} at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1792) ~[?:?] {} at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290) ~[?:?] {} at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016) ~[?:?] {} at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665) ~[?:?] {} at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598) ~[?:?] {} at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183) ~[?:?] {} Which seems to indicate that the burn times cannot be generated yet. I was generating my file during the "FMLCommonSetupEvent" event. How can I successfully retrieve the correct value for burnTime?
  3. I believe that I fully understand this concept now and will try to adapt my code from other blocks. Thanks!
  4. Thank you for clearing this up for me. So, if I replace my fields with properties and replace the position with a new block state whenever I want to update it, my code will work?
  5. I see what you mean. I have changed the variables to be private, which I believe should fix that problem.
  6. The field isn't static. I was referring to the instance of EnumFacing as the static value. It is being assigned to a field that is public. Therefore, each block should be able to edit these variables individually.
  7. The code setting the default state is actually part of my constructor. The direction variable is a static value stored into a public variable. Here's my whole class: package mymod.blocks; import java.sql.ResultSet; import java.util.List; import java.util.Random; import org.lwjgl.input.Keyboard; import library.blocks.LibBlockOre; import library.util.Actions; import mymod.Main; import mymod.MyActions; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.IBlockState; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; public class MyBlock1 extends LibBlockOre { public double range = 3; public int height = 2; public EnumFacing direction; public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public MyBlock1(String registryName, String harvestTool, int harvestLevel, EnumFacing facing) { super(registryName, harvestTool, harvestLevel); this.setCreativeTab(Main.my_creative_tab_1); this.setHardness(10.0F); this.setLightLevel(0.75F); this.setResistance(10000.0F); this.direction = facing; this.setDefaultState(blockState.getBaseState().withProperty(FACING, this.direction)); } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (playerIn.isCreative()) { if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { this.range ++; Actions.chatAtPlayer(playerIn, TextFormatting.GOLD + "Range: " + TextFormatting.RESET + this.range); } else if (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) { this.height ++; Actions.chatAtPlayer(playerIn, TextFormatting.GOLD + "Height: " + TextFormatting.RESET + this.height); } else if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) { this.range --; Actions.chatAtPlayer(playerIn, TextFormatting.GOLD + "Range: " + TextFormatting.RESET + this.range); } else if (Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)) { this.height --; Actions.chatAtPlayer(playerIn, TextFormatting.GOLD + "Height: " + TextFormatting.RESET + this.height); } else { Actions.chatAtPlayer(playerIn, TextFormatting.GOLD + "Range: " + TextFormatting.RESET + this.range); Actions.chatAtPlayer(playerIn, TextFormatting.GOLD + "Height: " + TextFormatting.RESET + this.height); } } return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ); } @Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { state = state.withProperty(FACING, this.direction); if (worldIn.isRemote) { for (Entity i : MyActions.getEntities(worldIn)) { if (i.getPosition().getY() >= pos.getY() + this.height && MyActions.distanceTo(pos.getX(), pos.getY(), pos.getZ(), i.getPosition().getX(), i.getPosition().getY(), i.getPosition().getZ()) <= this.range) { double speed = MyActions.getPersistentNbtData(i).getDouble("Tower Speed"); boolean isTower = MyActions.getPersistentNbtData(i).getBoolean("Is Tower?"); if (speed > 0 && isTower) { //These directions are incompatible with the directional methods used. if (!(this.direction == EnumFacing.UP || this.direction == EnumFacing.DOWN)) { MyActions.setEntityRotation(i, MyActions.stringFormEnumFacing(this.direction)); } //Set motion to control where the entity goes. switch (state.getValue(FACING)) { case NORTH: i.setVelocity(0, 0, speed * -1); break; case SOUTH: i.setVelocity(0, 0, speed * 1); break; case EAST: i.setVelocity(speed * 1, 0, 0); break; case WEST: i.setVelocity(speed * 1, 0, 0); break; case UP: i.setVelocity(0, speed * 1, 0); break; case DOWN: i.setVelocity(0, speed * -1, 0); break; } } } } } super.updateTick(worldIn, pos, state, rand); } } My code uses a lot of methods coming from custom classes. Tell me if you would like the code for those classes.
  8. I have a block that is like a conveyor belt. I want the block to always point in the direction that it will push the entity. I am aware that the block direction is defined by the block state, so I set the default block state using this code: public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); this.setDefaultState(blockState.getBaseState().withProperty(FACING, this.direction)); And attempted to update the block state with this code: @Override public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { state = state.withProperty(FACING, this.direction); } However, when the block is placed into the world, the block does not face the correct direction. What should I do?
  9. You can make the player move by editing x y and z motion variables or using the addVelocity method inside of the player class. I am not sure about digging, but I know you can make the player swing it's arm.
  10. I thought that the chunks would stay loaded after I spawned the entities, but I see that I have thought wrong. If the original Minecraft structures use it, then I should be fine with this.
  11. I want to spawn an entity inside my generated structure, but they keep despawning when the structure gets too far away. In order to avoid this, I am forcing the mobs I find to persist in the world, But this uses a lot of memory, as all of those chunks with the structure get loaded into memory until the mob dies. I am aware that structures such as the end city and woodland mansion do not seem to have this problem. How do I do this?
  12. I need to clone an entity when I spawn it so that I can have multiple of the same entity in the world at once. I use this code: //If we are on the client side if (!worldIn.isRemote) { Entity entity = ((Entity) thingToPlace); Entity entity2 = (Entity) EntityList.createEntityFromNBT(entity.getEntityData(), worldIn); //Set the EntitY's location entity2.setPosition(pos.getX(), pos.getY(), pos.getZ()); //Spawn the entity worldIn.spawnEntity(entity2); } I got a null pointer exception on that code, and I figured out it was because the value "id" was not set in the nbt I passed, so Minecraft skipped the entity and returned null. I added this code: entity.getEntityData().setString("id", entity.getName()); and that seemed to work, but I am not sure if this is what I am supposed to do and if this will cause problems. What is the proper way to solve this problem?
  13. There is a small chance that you would be able to copy the method to your own class and change it to edit the player externally.
  14. I am having problems setting the scoreboard objective display slot. I have a simple score called "score" (for testing purposes), and I want to set the slot to be in the sidebar. I created the score through my code using this method: /** * Set the specified score of the entity. Will create score is score does not exist. * * @param world * @param entity * @param objective * @param value */ public static void setScore(World world, Entity entity, String objective, int value) { if (entity instanceof EntityPlayer) { world.getScoreboard().getOrCreateScore(entity.getName(), world.getScoreboard().getObjective(objective)).setScorePoints(value); //world.getScoreboard().broadcastScoreUpdate(entity.getName(), world.getScoreboard().getObjective(objective)); } else { world.getScoreboard().getOrCreateScore(entity.getCachedUniqueIdString(), world.getScoreboard().getObjective(objective)).setScorePoints(value); //world.getScoreboard().broadcastScoreUpdate(entity.getCachedUniqueIdString(), world.getScoreboard().getObjective(objective)); } } When I try to run the command for this, I get the error that the score doesn't exist. When I try to do it from this method: /** * Set the display slot of the score. * * Can be list, sidebar, or belowName. * * @param world * @param slot * @param objective */ public static void setScoreDisplaySlot(World world, String slot, String objective) { Scoreboard scoreboard = world.getScoreboard(); int i = Scoreboard.getObjectiveDisplaySlotNumber(slot); ScoreObjective objectiveToUse = scoreboard.getObjective(objective); scoreboard.setObjectiveInDisplaySlot(i, objectiveToUse); } (I got that method from the CommandScore class) nothing happens. If I try to create the score in the function using this code: if (!scoreboard.getObjectiveNames().contains(objective)) { scoreboard.addScoreObjective(objective, IScoreCriteria.DUMMY); } the code in my statement runs, but I get an error that the score already existed. If the score already existed, then the command would have been able to sense it, and my code to create the objective should not have run. Getting and setting the score seems to work perfectly fine in the code.
  15. I have a mod that can run commands. But I cannot catch the result of the command it runs. When my mod edits the scoreboard of an entity, it should have a way to get the current score of a specific objective of that entity. I do not need a way to edit the score, as I can just use commands for that. I have an algorithm that works for players, but I do not know how to get the score from an entity (I have used scores on entities using command blocks before, so I know it is possible). My algorithm is here: /** * Get the specified score of the specified entity. Will create objective if it does not exist. * * @param world * @param entity * @param objective * @param value */ public static int getScore(World world, Entity entity, String objective) { return world.getScoreboard().getOrCreateScore(entity.getName(), world.getScoreboard().getObjective(objective)).getScorePoints(); }
  16. I need to get the 4-way cardinal direction of an entity in forge 1.12. I currently have code that partially does it that I found on the internet, but it does not always get the exact direction. For example, it might return west when I am facing east. The debug screen does exactly what I want, but I am not sure where to find the code for that. My current code: /** * Get the direction the entity is facing. Four possibilities. * * @param source * @return */ public static String getDirection(Entity source) { String dir = ""; float y = source.rotationYaw; if( y < 0 ){ y += 360; } y %= 360; int i = (int)(y / 90); if(i == 1){dir = "west";} else if (i == 2) {dir = "north";} else if (i == 3) {dir = "east";} else {dir = "south";} return dir; }
  17. I am using world.setBlockState() to place blocks in the world. I want to place down a chest that has stuff in it into the world. So far, I have found out how to place down the empty chest using this code: world.setBlockState(pos, Blocks.chest.getDefaultState().withProperty(BlockChest.FACING, EnumFacing.NORTH)); However, I understand that I need to edit the tile entity to put stuff in the chest. But I cannot find any way to access the tile entity through the block state. I need to edit it through the block state because getDefaultState() will override what I put in the chest. Is there any way to get the block state without overriding chest contents, or add chest contents through the block state?
  18. Ok, so if it is coming from the player, would that be the y-axis?
  19. I am trying to create a new shulker bullet, so I looked at what is required to instantiate one. I need a world, an owner, a target, and an Axis called p_i46772_4_. I know what to specify for almost all of those, but p_i46772_4_ got me confused. I looked at the type class for it and couldn't even figure out how to instantiate a variable of that type. What is p_i46772_4_, what must it be to summon my shulker shell, and how can I specify it?
×
×
  • Create New...

Important Information

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