Posted August 18, 20178 yr Hello! I am getting butchers to harvest meat from animals and I need said animals to be unharvestable to villagers for 24000 ticks. My issue is that I want the butchers to harvest from other mobs in that time so I can't just disallow the butchers from harvesting mobs for that period. How do I this without overriding said mob and creating a new entity since I want compatibility with other mods?
August 18, 20178 yr You can create a world data extension with a HashMap or similar collection where you map the entities to the time since last harvested, and update using the server tick event or world tick event. You would only need to add to the map when a successful harvest attempt happens (you don't have to have all the cows in the world in the map for example), and you could delete entries when the timer counts to zero or the entity dies. So it could be a fairly small and efficient map. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
August 18, 20178 yr Author 8 minutes ago, jabelar said: You can create a world data extension with a HashMap or similar collection where you map the entities to the time since last harvested, and update using the server tick event or world tick event. You would only need to add to the map when a successful harvest attempt happens (you don't have to have all the cows in the world in the map for example), and you could delete entries when the timer counts to zero or the entity dies. So it could be a fairly small and efficient map. Hmm, that sounds interesting and very useful. Unfortunately, I do not know what a HashMap is? Could you explain what a HashMap is and the basics how to do one? Thanks for the help!
August 18, 20178 yr HashMap is a common Java collection. It is just an implementation of the Map interface. A map just means there is a key and a value so you can look them up. So in this case you would add each entity as a "key" and the initial wait value as the "value". Then each tick you would iterate (loop) through the list of keys and for each on you would read the value and then set the value to one less (count down) and check if it hit zero (in which case you would remove the entry from the map). Whenever a butcher tries to harvest an entity you would just check if the entity exists as a key in the map, if it does it means it is not yet harvestable. Just search Google for Java HashMap examples. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
August 18, 20178 yr Whut. How about applying a Capability to the animals that stores the last world-time they were harvested? The butchers would then query that, do a calculation to see if that value is more than 24000 ticks ago, and then perform an action based on the result. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
August 18, 20178 yr Author 9 minutes ago, Draco18s said: Whut. How about applying a Capability to the animals that stores the last world-time they were harvested? The butchers would then query that, do a calculation to see if that value is more than 24000 ticks ago, and then perform an action based on the result. Where would I get the world-time?
August 18, 20178 yr The...world...? All entities have a reference to it. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
August 18, 20178 yr Author 2 hours ago, Draco18s said: The...world...? All entities have a reference to it. Alright, I have set up a basic capability, do I have to do anything for it to work client side or is that not necessary since the AI is doing it all. Also, how do I access this capability from my AI file?
August 19, 20178 yr 23 minutes ago, OrangeVillager61 said: Alright, I have set up a basic capability, do I have to do anything for it to work client side or is that not necessary since the AI is doing it all. Also, how do I access this capability from my AI file? If it's all AI, no, you don't need to do anything for the client. As for the capability, use GetCapability(...) on the entity in question. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
August 19, 20178 yr Author 22 minutes ago, Draco18s said: If it's all AI, no, you don't need to do anything for the client. As for the capability, use GetCapability(...) on the entity in question. Okay, what does it want for the capability augment? The provider? Edited August 19, 20178 yr by OrangeVillager61
August 19, 20178 yr Author Nevermind, I found what it needed. Lastly, how do I compare the past world time to the current one? Edited August 19, 20178 yr by OrangeVillager61
August 19, 20178 yr They're longs. Do subtraction. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
August 19, 20178 yr Author 1 minute ago, Draco18s said: They're longs. Do subtraction. Okay, so are the world times based on number of ticks the world has had?
August 19, 20178 yr Read the javadoc Yes Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
August 19, 20178 yr Author I seem to be having an issue with the capability. I can't find said issue though. public class HarvestTimeProvider implements ICapabilitySerializable<NBTBase>{ @CapabilityInject(IHarvestTime.class) public static final Capability<IHarvestTime> CAPABILITY_HARVEST_ANIMAL_TIME = null; private IHarvestTime instance = CAPABILITY_HARVEST_ANIMAL_TIME.getDefaultInstance(); @Override public boolean hasCapability(Capability<?> capability, EnumFacing facing) { return capability == CAPABILITY_HARVEST_ANIMAL_TIME; } @Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { return capability == CAPABILITY_HARVEST_ANIMAL_TIME ? CAPABILITY_HARVEST_ANIMAL_TIME.<T> cast(this.instance) : null; } @Override public NBTBase serializeNBT() { return CAPABILITY_HARVEST_ANIMAL_TIME.getStorage().writeNBT(CAPABILITY_HARVEST_ANIMAL_TIME, this.instance, null); } @Override public void deserializeNBT(NBTBase nbt) { CAPABILITY_HARVEST_ANIMAL_TIME.getStorage().readNBT(CAPABILITY_HARVEST_ANIMAL_TIME, this.instance, null, nbt); } } public class HarvestTimeUser implements IHarvestTime{ private long time = 0; @Override public void setTime(long l) { this.time = l; } @Override public long get_time() { return time; } } public interface IHarvestTime { void setTime(long l); long get_time(); } public class IvCapabilities { public static void regsiterCapabilties() { CapabilityManager.INSTANCE.register(IHarvestTime.class, new IHarvestTimeStorage(), HarvestTimeUser.class); } public static class IHarvestTimeStorage implements IStorage<IHarvestTime> { @Override public NBTBase writeNBT(Capability<IHarvestTime> capability, IHarvestTime instance, EnumFacing side) { return new NBTTagLong (instance.get_time()); } @Override public void readNBT(Capability<IHarvestTime> capability, IHarvestTime instance, EnumFacing side, NBTBase nbt) { instance.setTime(((NBTPrimitive) nbt).getLong()); } } } public class AttachCapabilties { public static final ResourceLocation HARVEST_TIME_CAP = new ResourceLocation(Reference.MOD_ID, "Harvest_Time"); @SubscribeEvent public void AttachCapToEntity (AttachCapabilitiesEvent<Entity> event) { if (event.getObject() instanceof EntityAnimal) { event.addCapability(HARVEST_TIME_CAP, new HarvestTimeProvider()); } } } When I'm using it: if (this.villagerObj.world.getWorldTime() - entity.getCapability(HarvestTimeProvider.CAPABILITY_HARVEST_ANIMAL_TIME, null).get_time() < 24000 || entity.getCapability(HarvestTimeProvider.CAPABILITY_HARVEST_ANIMAL_TIME, null).get_time() == 0) { System.out.println("Entity has been harvested"); return false; }
August 19, 20178 yr Author On 8/18/2017 at 4:53 PM, Draco18s said: Whut. How about applying a Capability to the animals that stores the last world-time they were harvested? The butchers would then query that, do a calculation to see if that value is more than 24000 ticks ago, and then perform an action based on the result. Above post Forgot to quote this there. Edited August 19, 20178 yr by OrangeVillager61
August 19, 20178 yr Author Fixed that bug but the butcher task still doesn't do anything. Making a new thread.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.