Skip to content

Commit

Permalink
Make fox DataWatcher IDs configurable (cc #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
makamys committed Nov 15, 2023
1 parent d9ae747 commit a19975c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
11 changes: 11 additions & 0 deletions src/main/java/makamys/dmod/ConfigDMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public class ConfigDMod {
public static List<Class<Entity>> rabbitEntities;
public static EntityFox.AbilityMode foxAbilityMode;
public static float foxExpModifier;
public static int foxDataWatcherIdOwner;
public static int foxDataWatcherIdOtherTrusted;
public static int foxDataWatcherIdType;
public static int foxDataWatcherIdFoxFlags;
public static int foxDataWatcherIdExperience;

public static boolean wolvesTargetFoxes;
public static ForceableBoolean lootingFoxFix;
Expand Down Expand Up @@ -115,6 +120,12 @@ public static void reload(boolean early) {
foxAbilityMode = getEnum(config, "foxAbilityMode", "fox", EntityFox.AbilityMode.NORMAL, "NORMAL: Foxes unlock abilities as they level up\nUNLOCK_ALL: All abilities are unlocked from the start\nUNLOCK_NONE: No abilities will ever be unlocked\nNote: changing this won't affect the amount of exp foxes have, just whether the abilities will be enabled or not");
foxExpModifier = config.getFloat("foxExpModifier", "Fox", 1f, 0f, Float.POSITIVE_INFINITY, "The EXP foxes earn will get multiplied by this value.");

foxDataWatcherIdOwner = config.getInt("0_owner", "fox.datawatcher_ids", 18, 0, Integer.MAX_VALUE, "Vanilla uses up slots 0..1 and 6..12. The maximum ID is 31 if no ID extension mod is present.");
foxDataWatcherIdOtherTrusted = config.getInt("1_otherTrusted", "fox.datawatcher_ids", 19, 0, Integer.MAX_VALUE, "");
foxDataWatcherIdType = config.getInt("2_type", "fox.datawatcher_ids", 20, 0, Integer.MAX_VALUE, "");
foxDataWatcherIdFoxFlags = config.getInt("3_foxFlags", "fox.datawatcher_ids", 21, 0, Integer.MAX_VALUE, "");
foxDataWatcherIdExperience = config.getInt("4_experience", "fox.datawatcher_ids", 22, 0, Integer.MAX_VALUE, "");

if(!early) {
foxBreedingItems =
resolveItemListOrDefault(config, "foxBreedingItems", "Fox", new String[]{"etfuturum:sweet_berries"}, "Falls back to wheat if none of the items can be resolved", Items.wheat);
Expand Down
46 changes: 23 additions & 23 deletions src/main/java/makamys/dmod/entity/EntityFox.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import static makamys.dmod.DModConstants.LOGGER;
import static makamys.dmod.DModConstants.MODID;
import static makamys.dmod.entity.EntityFox.Ability.*;
import static makamys.dmod.ConfigDMod.foxDataWatcherIdOwner;
import static makamys.dmod.ConfigDMod.foxDataWatcherIdOtherTrusted;
import static makamys.dmod.ConfigDMod.foxDataWatcherIdType;
import static makamys.dmod.ConfigDMod.foxDataWatcherIdFoxFlags;
import static makamys.dmod.ConfigDMod.foxDataWatcherIdExperience;

import java.util.Arrays;
import java.util.Comparator;
Expand Down Expand Up @@ -93,11 +98,6 @@
import net.minecraftforge.common.BiomeDictionary;

public class EntityFox extends EntityAnimalFuture implements ITameable {
private static final int OWNER = 18;
private static final int OTHER_TRUSTED = 19;
private static final int TYPE = 20;
private static final int FOX_FLAGS = 21;
private static final int EXPERIENCE = 22;
private static final IEntitySelector PICKABLE_DROP_FILTER;
private static final IEntitySelector FOOD_DROP_FILTER;
private static final IEntitySelector TOOL_DROP_FILTER;
Expand Down Expand Up @@ -135,11 +135,11 @@ public EntityFox(World world) {

protected void entityInit() {
super.entityInit();
this.dataWatcher.addObject(OWNER, String.valueOf(""));
this.dataWatcher.addObject(OTHER_TRUSTED, String.valueOf(""));
this.dataWatcher.addObject(TYPE, Byte.valueOf((byte) 0));
this.dataWatcher.addObject(FOX_FLAGS, Byte.valueOf((byte) 0));
this.dataWatcher.addObject(EXPERIENCE, Float.valueOf(0));
this.dataWatcher.addObject(foxDataWatcherIdOwner, String.valueOf(""));
this.dataWatcher.addObject(foxDataWatcherIdOtherTrusted, String.valueOf(""));
this.dataWatcher.addObject(foxDataWatcherIdType, Byte.valueOf((byte) 0));
this.dataWatcher.addObject(foxDataWatcherIdFoxFlags, Byte.valueOf((byte) 0));
this.dataWatcher.addObject(foxDataWatcherIdExperience, Float.valueOf(0));
}

protected void initTasks() {
Expand Down Expand Up @@ -211,7 +211,7 @@ public String getEatSound(ItemStack stack) {
private void trustAllPlayers() {
for(Object obj : ((WorldServer)worldObj).playerEntities) {
UUID uuid = ((Entity)obj).getUniqueID();
this.dataWatcher.updateObject(OWNER, uuid.toString());
this.dataWatcher.updateObject(foxDataWatcherIdOwner, uuid.toString());
}
}

Expand Down Expand Up @@ -407,37 +407,37 @@ public float getEyeHeight() {
}

public EntityFox.Type getFoxType() {
return EntityFox.Type.fromId(dataWatcher.getWatchableObjectByte(TYPE));
return EntityFox.Type.fromId(dataWatcher.getWatchableObjectByte(foxDataWatcherIdType));
}

private void setType(EntityFox.Type type) {
this.dataWatcher.updateObject(TYPE, Byte.valueOf((byte)type.getId()));
this.dataWatcher.updateObject(foxDataWatcherIdType, Byte.valueOf((byte)type.getId()));
}

private void setExperience(float exp) {
this.dataWatcher.updateObject(EXPERIENCE, exp);
this.dataWatcher.updateObject(foxDataWatcherIdExperience, exp);
}

private void addExperience(float exp) {
setExperience(getExperience() + exp);
}

public float getExperience() {
return this.dataWatcher.getWatchableObjectFloat(EXPERIENCE);
return this.dataWatcher.getWatchableObjectFloat(foxDataWatcherIdExperience);
}

private List<UUID> getTrustedUuids() {
List<UUID> list = Lists.newArrayList();
list.add(DUtil.UUIDorNullFromString(this.dataWatcher.getWatchableObjectString(OWNER)));
list.add(DUtil.UUIDorNullFromString(this.dataWatcher.getWatchableObjectString(OTHER_TRUSTED)));
list.add(DUtil.UUIDorNullFromString(this.dataWatcher.getWatchableObjectString(foxDataWatcherIdOwner)));
list.add(DUtil.UUIDorNullFromString(this.dataWatcher.getWatchableObjectString(foxDataWatcherIdOtherTrusted)));
return list;
}

private void addTrustedUuid(@Nullable UUID uuid) {
if (!this.dataWatcher.getWatchableObjectString(OWNER).isEmpty()) {
this.dataWatcher.updateObject(OTHER_TRUSTED, uuid.toString());
if (!this.dataWatcher.getWatchableObjectString(foxDataWatcherIdOwner).isEmpty()) {
this.dataWatcher.updateObject(foxDataWatcherIdOtherTrusted, uuid.toString());
} else {
this.dataWatcher.updateObject(OWNER, uuid.toString());
this.dataWatcher.updateObject(foxDataWatcherIdOwner, uuid.toString());
}
}

Expand Down Expand Up @@ -531,15 +531,15 @@ private void setSleeping(boolean sleeping) {

private void setFoxFlag(int mask, boolean value) {
if (value) {
this.dataWatcher.updateObject(FOX_FLAGS, (byte)((Byte)this.dataWatcher.getWatchableObjectByte(FOX_FLAGS) | mask));
this.dataWatcher.updateObject(foxDataWatcherIdFoxFlags, (byte)((Byte)this.dataWatcher.getWatchableObjectByte(foxDataWatcherIdFoxFlags) | mask));
} else {
this.dataWatcher.updateObject(FOX_FLAGS, (byte)((Byte)this.dataWatcher.getWatchableObjectByte(FOX_FLAGS) & ~mask));
this.dataWatcher.updateObject(foxDataWatcherIdFoxFlags, (byte)((Byte)this.dataWatcher.getWatchableObjectByte(foxDataWatcherIdFoxFlags) & ~mask));
}

}

private boolean getFoxFlag(int bitmask) {
return ((Byte)this.dataWatcher.getWatchableObjectByte(FOX_FLAGS) & bitmask) != 0;
return ((Byte)this.dataWatcher.getWatchableObjectByte(foxDataWatcherIdFoxFlags) & bitmask) != 0;
}

// TODO for dispenser support
Expand Down

0 comments on commit a19975c

Please sign in to comment.