Skip to content

Commit

Permalink
Reorganize some code, just because
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Schifferer <[email protected]>
  • Loading branch information
paulyhedral committed Jan 1, 2024
1 parent 58851a1 commit ca3222a
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 225 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/sweetrpg/catherder/CatHerder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.sweetrpg.catherder.client.ClientSetup;
import com.sweetrpg.catherder.client.entity.render.world.BedFinderRenderer;
import com.sweetrpg.catherder.client.event.ClientEventHandler;
import com.sweetrpg.catherder.common.Capabilities;
import com.sweetrpg.catherder.common.lib.Capabilities;
import com.sweetrpg.catherder.common.CommonSetup;
import com.sweetrpg.catherder.common.addon.AddonManager;
import com.sweetrpg.catherder.common.command.CatRespawnCommand;
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/sweetrpg/catherder/common/CommonSetup.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.sweetrpg.catherder.common;

import com.sweetrpg.catherder.api.feature.FoodHandler;
import com.sweetrpg.catherder.api.feature.InteractHandler;
import com.sweetrpg.catherder.common.command.CatRespawnCommand;
import com.sweetrpg.catherder.common.config.ConfigHandler;
import com.sweetrpg.catherder.common.entity.CatEntity;
import com.sweetrpg.catherder.common.entity.FishFoodHandler;
import com.sweetrpg.catherder.common.entity.HelmetInteractHandler;
import com.sweetrpg.catherder.common.entity.MeatFoodHandler;
import com.sweetrpg.catherder.common.event.FishFoodHandler;
import com.sweetrpg.catherder.common.network.PacketHandler;
import com.sweetrpg.catherder.common.registry.ModItems;
import com.sweetrpg.catherder.common.talent.HappyEaterTalent;
import com.sweetrpg.catherder.common.world.WildCropGeneration;
import com.sweetrpg.catherder.common.world.gen.WildCropGeneration;
import net.minecraft.world.level.block.ComposterBlock;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;

Expand All @@ -25,7 +22,7 @@ public static void init(final FMLCommonSetupEvent event) {
FoodHandler.registerHandler(new FishFoodHandler());
FoodHandler.registerDynPredicate(HappyEaterTalent.INNER_DYN_PRED);

InteractHandler.registerHandler(new HelmetInteractHandler());
// InteractHandler.registerHandler(new HelmetInteractHandler());
ConfigHandler.initTalentConfig();
CatRespawnCommand.registerSerilizers();
CatEntity.initDataParameters();
Expand Down
26 changes: 12 additions & 14 deletions src/main/java/com/sweetrpg/catherder/common/entity/CatEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.sweetrpg.catherder.common.entity.ai.CatLieOnBedGoal;
import com.sweetrpg.catherder.common.entity.ai.CatSitOnBlockGoal;
import com.sweetrpg.catherder.common.entity.ai.*;
import com.sweetrpg.catherder.common.entity.serializers.DimensionDependantArg;
import com.sweetrpg.catherder.common.entity.misc.DimensionDependentArg;
import com.sweetrpg.catherder.common.entity.stats.StatsTracker;
import com.sweetrpg.catherder.common.lib.Constants;
import com.sweetrpg.catherder.common.registry.*;
Expand All @@ -27,7 +27,6 @@
import com.sweetrpg.catherder.common.util.NBTUtil;
import com.sweetrpg.catherder.common.util.Util;
import com.sweetrpg.catherder.common.util.WorldUtil;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -45,7 +44,6 @@
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.OldUsersConverter;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
Expand Down Expand Up @@ -126,9 +124,9 @@ public class CatEntity extends AbstractCatEntity {
private static final Cache<EntityDataAccessor<CatLevel>> CAT_LEVEL = Cache.make(() -> (EntityDataAccessor<CatLevel>) SynchedEntityData.defineId(CatEntity.class, ModSerializers.CAT_LEVEL_SERIALIZER.get().getSerializer()));
private static final Cache<EntityDataAccessor<EnumGender>> GENDER = Cache.make(() -> (EntityDataAccessor<EnumGender>) SynchedEntityData.defineId(CatEntity.class, ModSerializers.GENDER_SERIALIZER.get().getSerializer()));
private static final Cache<EntityDataAccessor<EnumMode>> MODE = Cache.make(() -> (EntityDataAccessor<EnumMode>) SynchedEntityData.defineId(CatEntity.class, ModSerializers.MODE_SERIALIZER.get().getSerializer()));
private static final Cache<EntityDataAccessor<DimensionDependantArg<Optional<BlockPos>>>> CAT_TREE_LOCATION = Cache.make(() -> (EntityDataAccessor<DimensionDependantArg<Optional<BlockPos>>>) SynchedEntityData.defineId(CatEntity.class, ModSerializers.CAT_TREE_LOC_SERIALIZER.get().getSerializer()));
private static final Cache<EntityDataAccessor<DimensionDependantArg<Optional<BlockPos>>>> CAT_BOWL_LOCATION = Cache.make(() -> (EntityDataAccessor<DimensionDependantArg<Optional<BlockPos>>>) SynchedEntityData.defineId(CatEntity.class, ModSerializers.CAT_TREE_LOC_SERIALIZER.get().getSerializer()));
private static final Cache<EntityDataAccessor<DimensionDependantArg<Optional<BlockPos>>>> LITTERBOX_LOCATION = Cache.make(() -> (EntityDataAccessor<DimensionDependantArg<Optional<BlockPos>>>) SynchedEntityData.defineId(CatEntity.class, ModSerializers.CAT_TREE_LOC_SERIALIZER.get().getSerializer()));
private static final Cache<EntityDataAccessor<DimensionDependentArg<Optional<BlockPos>>>> CAT_TREE_LOCATION = Cache.make(() -> (EntityDataAccessor<DimensionDependentArg<Optional<BlockPos>>>) SynchedEntityData.defineId(CatEntity.class, ModSerializers.CAT_TREE_LOC_SERIALIZER.get().getSerializer()));
private static final Cache<EntityDataAccessor<DimensionDependentArg<Optional<BlockPos>>>> CAT_BOWL_LOCATION = Cache.make(() -> (EntityDataAccessor<DimensionDependentArg<Optional<BlockPos>>>) SynchedEntityData.defineId(CatEntity.class, ModSerializers.CAT_TREE_LOC_SERIALIZER.get().getSerializer()));
private static final Cache<EntityDataAccessor<DimensionDependentArg<Optional<BlockPos>>>> LITTERBOX_LOCATION = Cache.make(() -> (EntityDataAccessor<DimensionDependentArg<Optional<BlockPos>>>) SynchedEntityData.defineId(CatEntity.class, ModSerializers.CAT_TREE_LOC_SERIALIZER.get().getSerializer()));
private static final Cache<EntityDataAccessor<Integer>> ORIGINAL_BREED = Cache.make(() -> (EntityDataAccessor<Integer>) SynchedEntityData.defineId(CatEntity.class, ModSerializers.ORIGINAL_BREED_SERIALIZER.get().getSerializer()));

public final Map<Integer, Object> objects = new HashMap<>();
Expand Down Expand Up @@ -198,9 +196,9 @@ protected void defineSynchedData() {
this.entityData.define(SIZE, (byte) 3);
this.entityData.define(ORIGINAL_BREED_INT, 0);
this.entityData.define(TOY_VARIANT, ItemStack.EMPTY);
this.entityData.define(CAT_TREE_LOCATION.get(), new DimensionDependantArg<>(() -> EntityDataSerializers.OPTIONAL_BLOCK_POS));
this.entityData.define(CAT_BOWL_LOCATION.get(), new DimensionDependantArg<>(() -> EntityDataSerializers.OPTIONAL_BLOCK_POS));
this.entityData.define(LITTERBOX_LOCATION.get(), new DimensionDependantArg<>(() -> EntityDataSerializers.OPTIONAL_BLOCK_POS));
this.entityData.define(CAT_TREE_LOCATION.get(), new DimensionDependentArg<>(() -> EntityDataSerializers.OPTIONAL_BLOCK_POS));
this.entityData.define(CAT_BOWL_LOCATION.get(), new DimensionDependentArg<>(() -> EntityDataSerializers.OPTIONAL_BLOCK_POS));
this.entityData.define(LITTERBOX_LOCATION.get(), new DimensionDependentArg<>(() -> EntityDataSerializers.OPTIONAL_BLOCK_POS));
// this.entityData.define(IS_LYING, false);
this.entityData.define(RELAX_STATE_ONE, false);
}
Expand Down Expand Up @@ -1309,7 +1307,7 @@ public void addAdditionalSaveData(CompoundTag compound) {
compound.putInt("original_breed", this.getOriginalBreed());
NBTUtil.writeItemStack(compound, "fetchItem", this.getToyVariant());

DimensionDependantArg<Optional<BlockPos>> bedsData = this.entityData.get(CAT_TREE_LOCATION.get());
DimensionDependentArg<Optional<BlockPos>> bedsData = this.entityData.get(CAT_TREE_LOCATION.get());

if(!bedsData.isEmpty()) {
ListTag bedsList = new ListTag();
Expand All @@ -1324,7 +1322,7 @@ public void addAdditionalSaveData(CompoundTag compound) {
compound.put("beds", bedsList);
}

DimensionDependantArg<Optional<BlockPos>> bowlsData = this.entityData.get(CAT_BOWL_LOCATION.get());
DimensionDependentArg<Optional<BlockPos>> bowlsData = this.entityData.get(CAT_BOWL_LOCATION.get());

if(!bowlsData.isEmpty()) {
ListTag bowlsList = new ListTag();
Expand Down Expand Up @@ -1555,7 +1553,7 @@ public void readAdditionalSaveData(CompoundTag compound) {
}

// cat tree
DimensionDependantArg<Optional<BlockPos>> bedsData = this.entityData.get(CAT_TREE_LOCATION.get()).copyEmpty();
DimensionDependentArg<Optional<BlockPos>> bedsData = this.entityData.get(CAT_TREE_LOCATION.get()).copyEmpty();

try {
if(compound.contains("beds", Tag.TAG_LIST)) {
Expand All @@ -1578,7 +1576,7 @@ public void readAdditionalSaveData(CompoundTag compound) {
this.entityData.set(CAT_TREE_LOCATION.get(), bedsData);

// cat bowl
DimensionDependantArg<Optional<BlockPos>> bowlsData = this.entityData.get(CAT_BOWL_LOCATION.get()).copyEmpty();
DimensionDependentArg<Optional<BlockPos>> bowlsData = this.entityData.get(CAT_BOWL_LOCATION.get()).copyEmpty();

try {
if(compound.contains("bowls", Tag.TAG_LIST)) {
Expand All @@ -1601,7 +1599,7 @@ public void readAdditionalSaveData(CompoundTag compound) {
this.entityData.set(CAT_BOWL_LOCATION.get(), bowlsData);

// litterbox
DimensionDependantArg<Optional<BlockPos>> litterboxData = this.entityData.get(LITTERBOX_LOCATION.get()).copyEmpty();
DimensionDependentArg<Optional<BlockPos>> litterboxData = this.entityData.get(LITTERBOX_LOCATION.get()).copyEmpty();

try {
if(compound.contains("litterbox", Tag.TAG_LIST)) {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sweetrpg.catherder.common.entity.serializers;
package com.sweetrpg.catherder.common.entity.misc;

import net.minecraft.network.syncher.EntityDataSerializer;
import net.minecraft.resources.ResourceKey;
Expand All @@ -7,13 +7,13 @@
import java.util.*;
import java.util.function.Supplier;

public class DimensionDependantArg<T> implements Map<ResourceKey<Level>, T> {
public class DimensionDependentArg<T> implements Map<ResourceKey<Level>, T> {

private Supplier<EntityDataSerializer<T>> serializer;

public Map<ResourceKey<Level>, T> map = new HashMap<>();

public DimensionDependantArg(Supplier<EntityDataSerializer<T>> serializer) {
public DimensionDependentArg(Supplier<EntityDataSerializer<T>> serializer) {
this.serializer = serializer;
}

Expand All @@ -36,17 +36,17 @@ public EntityDataSerializer<T> getSerializer() {
return this.serializer.get();
}

public DimensionDependantArg<T> copy() {
DimensionDependantArg<T> clone = new DimensionDependantArg<>(this.serializer);
public DimensionDependentArg<T> copy() {
DimensionDependentArg<T> clone = new DimensionDependentArg<>(this.serializer);
clone.map.putAll(this.map);
return clone;
}

public DimensionDependantArg<T> copyEmpty() {
return new DimensionDependantArg<>(this.serializer);
public DimensionDependentArg<T> copyEmpty() {
return new DimensionDependentArg<>(this.serializer);
}

public DimensionDependantArg<T> set(ResourceKey<Level> dim, T value) {
public DimensionDependentArg<T> set(ResourceKey<Level> dim, T value) {
this.put(dim, value);
return this;
}
Expand All @@ -65,10 +65,10 @@ public String toString() {
public boolean equals(Object obj) {
if (obj.getClass() != this.getClass()) {
return false;
} else if (!(obj instanceof DimensionDependantArg)) {
} else if (!(obj instanceof DimensionDependentArg)) {
return false;
} else {
DimensionDependantArg<?> other = (DimensionDependantArg<?>) obj;
DimensionDependentArg<?> other = (DimensionDependentArg<?>) obj;
return this.map.equals(other.map);
}
}
Expand Down
Loading

0 comments on commit ca3222a

Please sign in to comment.