Skip to content

Commit

Permalink
Fixed all issues related to registry names
Browse files Browse the repository at this point in the history
Also fixed a bunch of other issues
Now launches
  • Loading branch information
GirafiStudios committed Jun 10, 2022
1 parent 508d6ad commit 87f8a53
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public ItemStack makeIcon() {

public Aquaculture() {
instance = this;
BIOME_TAG_CHECK = LootItemConditions.register(new ResourceLocation(Aquaculture.MOD_ID, "biome_tag_check").toString(), new BiomeTagCheck.BiomeTagCheckSerializer());
final IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
modBus.addListener(this::setupCommon);
modBus.addListener(this::setupClient);
Expand All @@ -59,7 +58,7 @@ public Aquaculture() {
}

private void setupCommon(FMLCommonSetupEvent event) {
FishWeightHandler.registerFishData();
event.enqueueWork(FishWeightHandler::registerFishData);
event.enqueueWork(AquaEntities::setSpawnPlacement);
event.enqueueWork(WormFarmBlock::addCompostables);
event.enqueueWork(AquaRecipes::registerBrewingRecipes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.Supplier;

public class Hook {
public static final HashMap<String, RegistryObject<HookItem>> HOOKS = new HashMap<>();
Expand All @@ -34,10 +35,10 @@ public class Hook {
private final double durabilityChance;
private final int luckModifier;
private final double doubleCatchChance;
private final SoundEvent catchSound;
private final Supplier<SoundEvent> catchSound;
private final List<TagKey<Fluid>> fluids;

private Hook(String name, String modID, ChatFormatting color, int minCatchable, int maxCatchable, Vec3 weight, double durabilityChance, int luckModifier, double doubleCatchChance, SoundEvent catchSound, List<TagKey<Fluid>> fluids) {
private Hook(String name, String modID, ChatFormatting color, int minCatchable, int maxCatchable, Vec3 weight, double durabilityChance, int luckModifier, double doubleCatchChance, Supplier<SoundEvent> catchSound, List<TagKey<Fluid>> fluids) {
this.name = name;
this.modID = modID;
this.color = color;
Expand Down Expand Up @@ -105,7 +106,7 @@ public double getDoubleCatchChance() {
}

public SoundEvent getCatchSound() {
return this.catchSound;
return this.catchSound.get();
}

public List<TagKey<Fluid>> getFluids() {
Expand All @@ -122,7 +123,7 @@ public static class HookBuilder {
private double durabilityChance;
private int luckModifier;
private double doubleCatchChance;
private SoundEvent catchSound;
private Supplier<SoundEvent> catchSound;
private final List<TagKey<Fluid>> fluids = new ArrayList<>();

HookBuilder() {
Expand Down Expand Up @@ -175,7 +176,7 @@ public HookBuilder setDoubleCatchChance(double doubleCatchChance) {
return this;
}

public HookBuilder setCatchSound(SoundEvent catchSound) {
public HookBuilder setCatchSound(Supplier<SoundEvent> catchSound) {
this.catchSound = catchSound;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Hooks {
public static final Hook HEAVY = new Hook.HookBuilder("heavy").setColor(ChatFormatting.BOLD).setWeight(new Vec3(0.6D, 0.15D, 0.6D)).build();
public static final Hook DOUBLE = new Hook.HookBuilder("double").setColor(ChatFormatting.DARK_GRAY).setDoubleCatchChance(0.10).build();
public static final Hook REDSTONE = new Hook.HookBuilder("redstone").setColor(ChatFormatting.RED).setCatchableWindow(35, 70).build();
public static final Hook NOTE = new Hook.HookBuilder("note").setColor(ChatFormatting.DARK_RED).setCatchSound(AquaSounds.BOBBER_NOTE.get()).build();
public static final Hook NOTE = new Hook.HookBuilder("note").setColor(ChatFormatting.DARK_RED).setCatchSound(AquaSounds.BOBBER_NOTE).build();
public static final Hook NETHER_STAR = new Hook.HookBuilder("nether_star").setColor(ChatFormatting.BLACK)/*.setFluid(FluidTags.LAVA)*/.setFluid(FluidTags.WATER).setDurabilityChance(0.50).setLuckModifier(1).build();
//Lava
//public static final Hook OBSIDIAN = new Hook.HookBuilder("obsidian").setColor(TextFormatting.DARK_PURPLE).setFluid(FluidTags.LAVA).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.teammetallurgy.aquaculture.entity.FishMountEntity;
import com.teammetallurgy.aquaculture.init.*;
import com.teammetallurgy.aquaculture.item.DyeableItem;
import com.teammetallurgy.aquaculture.misc.StackHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.client.gui.screens.MenuScreens;
Expand Down Expand Up @@ -64,7 +65,7 @@ public static void setupClient() {
public static void registerEntityRenders(EntityRenderersEvent.RegisterRenderers event) {
event.registerEntityRenderer(AquaEntities.BOBBER.get(), AquaBobberRenderer::new);
for (RegistryObject<EntityType<AquaFishEntity>> fish : FishRegistry.fishEntities) {
event.registerEntityRenderer(fish.get(), (context) -> new AquaFishRenderer(context, fish.get().getDescription().getString().equals("jellyfish")));
event.registerEntityRenderer(fish.get(), (context) -> new AquaFishRenderer(context, StackHelper.nameFromDescriptionID(fish.get().getDescriptionId()).equals("jellyfish")));
}
event.registerEntityRenderer(AquaEntities.WATER_ARROW.get(), TippableArrowRenderer::new);
event.registerEntityRenderer(AquaEntities.SPECTRAL_WATER_ARROW.get(), SpectralArrowRenderer::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.teammetallurgy.aquaculture.client.renderer.entity.model.*;
import com.teammetallurgy.aquaculture.entity.AquaFishEntity;
import com.teammetallurgy.aquaculture.entity.FishType;
import com.teammetallurgy.aquaculture.misc.StackHelper;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.TropicalFishModelB;
import net.minecraft.client.model.geom.ModelLayers;
Expand Down Expand Up @@ -64,9 +65,9 @@ public void render(@Nonnull AquaFishEntity fishEntity, float entityYaw, float pa
@Override
@Nonnull
public ResourceLocation getTextureLocation(@Nonnull AquaFishEntity fishEntity) {
Component location = fishEntity.getType().getDescription();
if (location != null) {
return new ResourceLocation(Aquaculture.MOD_ID, "textures/entity/fish/" + location.getString() + ".png");
String string = StackHelper.nameFromDescriptionID(fishEntity.getType().getDescriptionId());
if (!string.isEmpty()) {
return new ResourceLocation(Aquaculture.MOD_ID, "textures/entity/fish/" + string + ".png");
}
return DEFAULT_LOCATION;
}
Expand Down Expand Up @@ -107,9 +108,9 @@ protected void setupRotations(@Nonnull AquaFishEntity fishEntity, @Nonnull PoseS

@Override
protected void scale(AquaFishEntity fishEntity, @Nonnull PoseStack matrixStack, float partialTickTime) {
Component component = fishEntity.getType().getDescription();
String string = StackHelper.nameFromDescriptionID(fishEntity.getType().getDescriptionId());
float scale = 0.0F;
switch (component.getString()) {
switch (string) {
case "minnow" -> scale = 0.5F;
case "synodontis" -> scale = 0.8F;
case "brown_trout", "piranha" -> scale = 0.9F;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.teammetallurgy.aquaculture.entity.AquaFishEntity;
import com.teammetallurgy.aquaculture.entity.FishMountEntity;
import com.teammetallurgy.aquaculture.entity.FishType;
import com.teammetallurgy.aquaculture.misc.StackHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.Sheets;
Expand Down Expand Up @@ -59,9 +60,9 @@ public void render(@Nonnull FishMountEntity fishMount, float entityYaw, float pa

matrixStack.pushPose();
matrixStack.translate(-0.5D, -0.5D, -0.5D);
ResourceLocation id = new ResourceLocation(fishMount.getType().getDescriptionId());
if (id != null) {
ModelResourceLocation location = new ModelResourceLocation(id, ""); //Calling this instead of the fields for mod support'
String id = StackHelper.nameFromDescriptionID(fishMount.getType().getDescriptionId());
if (!id.isEmpty()) {
ModelResourceLocation location = new ModelResourceLocation(new ResourceLocation(Aquaculture.MOD_ID, id), ""); //Calling this instead of the fields for mod support'
rendererDispatcher.getModelRenderer().renderModel(matrixStack.last(), buffer.getBuffer(Sheets.solidBlockSheet()), null, manager.getModel(location), 1.0F, 1.0F, 1.0F, i, OverlayTexture.NO_OVERLAY);
}
matrixStack.popPose();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.teammetallurgy.aquaculture.entity;

import com.teammetallurgy.aquaculture.Aquaculture;
import com.teammetallurgy.aquaculture.entity.ai.goal.FollowTypeSchoolLeaderGoal;
import com.teammetallurgy.aquaculture.init.AquaItems;
import com.teammetallurgy.aquaculture.init.AquaSounds;
import com.teammetallurgy.aquaculture.misc.StackHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
Expand Down Expand Up @@ -61,7 +63,7 @@ public ItemStack getPickedResult(HitResult target) {
@Override
@Nonnull
public ItemStack getBucketItemStack() {
return new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(this.getType().getDescriptionId() + "_bucket")));
return new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(Aquaculture.MOD_ID, StackHelper.nameFromDescriptionID(this.getType().getDescriptionId()) + "_bucket")));
}

@Override
Expand Down Expand Up @@ -97,7 +99,7 @@ public EntityDimensions getDimensions(@Nonnull Pose pose) {
@Override
public void playerTouch(@Nonnull Player player) {
super.playerTouch(player);
if (Objects.equals(this.getType().toString(), AquaItems.JELLYFISH.get().toString())) {
if (Objects.equals(StackHelper.nameFromDescriptionID(this.getType().getDescriptionId()), StackHelper.nameFromDescriptionID(AquaItems.JELLYFISH.get().getDescriptionId()))) {
if (this.isAlive()) {
if (this.distanceToSqr(player) < 1.0D && player.hurt(DamageSource.mobAttack(this), 0.5F)) {
this.playSound(AquaSounds.JELLYFISH_COLLIDE.get(), 0.5F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.teammetallurgy.aquaculture.entity;

import com.teammetallurgy.aquaculture.Aquaculture;
import com.teammetallurgy.aquaculture.api.AquacultureAPI;
import com.teammetallurgy.aquaculture.init.AquaSounds;
import com.teammetallurgy.aquaculture.misc.StackHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -110,19 +112,20 @@ protected void recalculateBoundingBox() {
double z1 = this.getWidth() / 32.0D;
double z2 = this.getWidth() / 32.0D;
switch (this.direction.getAxis()) {
case X:
case X -> {
x1 = (this.direction.getStepX() < 0 ? 3.0D : 1.0D) / 32.0D;
x2 = (this.direction.getStepX() > 0 ? 3.0D : 1.0D) / 32.0D;
break;
case Y:
}
case Y -> {
y1 = (this.direction.getStepY() < 0 ? 3.0D : 1.0D) / 32.0D;
y2 = (this.direction.getStepY() > 0 ? 3.0D : 1.0D) / 32.0D;
z1 = 8.0D / 32.0D;
z2 = 8.0D / 32.0D;
break;
case Z:
}
case Z -> {
z1 = (this.direction.getStepZ() < 0 ? 3.0D : 1.0D) / 32.0D;
z2 = (this.direction.getStepZ() > 0 ? 3.0D : 1.0D) / 32.0D;
}
}
this.setBoundingBox(new AABB(posX - x1, posY - y1, posZ - z1, posX + x2, posY + y2, posZ + z2));
}
Expand Down Expand Up @@ -208,7 +211,7 @@ private void dropItemOrSelf(@Nullable Entity entity, boolean shouldDropSelf) {
}

private Item getItem() {
ResourceLocation location = new ResourceLocation(this.getType().getDescriptionId());
ResourceLocation location = new ResourceLocation(this.getType().getDescriptionId().replace("entity.", "").replace(".", ":"));
if (ForgeRegistries.ITEMS.containsKey(location)) {
return ForgeRegistries.ITEMS.getValue(location);
}
Expand Down Expand Up @@ -252,7 +255,7 @@ public void onSyncedDataUpdated(EntityDataAccessor<?> key) {
if (key.equals(ITEM)) {
ItemStack displayStack = this.getDisplayedItem();
if (displayStack != null && !displayStack.isEmpty()) {
EntityType entityType = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(displayStack.getItem().getDescriptionId()));
EntityType entityType = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(displayStack.getItem().getDescriptionId().replace("item.", "").replace(".", ":")));
if (entityType != null && entityType != EntityType.PIG) {
this.entity = entityType.create(this.level);
}
Expand All @@ -263,7 +266,7 @@ public void onSyncedDataUpdated(EntityDataAccessor<?> key) {
}

@Override
public void addAdditionalSaveData(CompoundTag compound) {
public void addAdditionalSaveData(@Nonnull CompoundTag compound) {
super.addAdditionalSaveData(compound);
if (!this.getDisplayedItem().isEmpty()) {
compound.put("Item", this.getDisplayedItem().save(new CompoundTag()));
Expand All @@ -273,7 +276,7 @@ public void addAdditionalSaveData(CompoundTag compound) {
}

@Override
public void readAdditionalSaveData(CompoundTag compound) {
public void readAdditionalSaveData(@Nonnull CompoundTag compound) {
super.readAdditionalSaveData(compound);
CompoundTag nbt = compound.getCompound("Item");
if (nbt != null && !nbt.isEmpty()) {
Expand Down Expand Up @@ -302,7 +305,8 @@ public InteractionResult interact(Player player, @Nonnull InteractionHand hand)
if (!this.level.isClientSide) {
if (this.getDisplayedItem().isEmpty()) {
Item heldItem = heldStack.getItem();
EntityType<?> entityType = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(heldItem.getDescriptionId()));
String id = heldItem.getDescriptionId().replace("item.", "").replace(".", ":");
EntityType<?> entityType = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(id));
if (entityType != EntityType.PIG && AquacultureAPI.FISH_DATA.getFish().contains(heldItem)) {
this.setDisplayedItem(heldStack);
if (!player.getAbilities().instabuild) {
Expand Down Expand Up @@ -338,10 +342,10 @@ protected void setRot(float yaw, float pitch) {

@Override
public void writeSpawnData(FriendlyByteBuf buffer) {
buffer.writeResourceLocation(new ResourceLocation(this.getType().getDescriptionId()));
buffer.writeResourceLocation(new ResourceLocation(Aquaculture.MOD_ID, StackHelper.nameFromDescriptionID(this.getType().getDescriptionId())));
}

@Override
public void readSpawnData(FriendlyByteBuf additionalData) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.teammetallurgy.aquaculture.entity.FishType;
import com.teammetallurgy.aquaculture.item.AquaFishBucket;
import com.teammetallurgy.aquaculture.item.FishMountItem;
import com.teammetallurgy.aquaculture.loot.BiomeTagCheck;
import com.teammetallurgy.aquaculture.misc.StackHelper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
Expand All @@ -17,10 +18,12 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.storage.loot.predicates.LootItemConditions;
import net.minecraftforge.event.entity.EntityAttributeCreationEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent;
import net.minecraftforge.registries.RegistryObject;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -66,6 +69,13 @@ public static RegistryObject<Item> register(@Nonnull Supplier<Item> initializer,
return AquaItems.register(initializer, name);
}

@SubscribeEvent
public static void registerFishies(RegisterEvent event) {
if (event.getRegistryKey().equals(ForgeRegistries.Keys.LOOT_MODIFIER_SERIALIZERS)) {
Aquaculture.BIOME_TAG_CHECK = LootItemConditions.register(new ResourceLocation(Aquaculture.MOD_ID, "biome_tag_check").toString(), new BiomeTagCheck.BiomeTagCheckSerializer());
}
}

@SubscribeEvent
public static void addFishEntity0Attributes(EntityAttributeCreationEvent event) {
for (RegistryObject<EntityType<AquaFishEntity>> entityType : fishEntities) {
Expand All @@ -78,7 +88,7 @@ public static void addCatBreeding() {
Ingredient catBreedingItems = Cat.TEMPT_INGREDIENT;
Ingredient ocelotBreedingItems = Ocelot.TEMPT_INGREDIENT;
List<ItemStack> aquaFish = new ArrayList<>();
fishEntities.forEach(f -> aquaFish.add(new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(f.get().getDescriptionId())))));
fishEntities.forEach(f -> aquaFish.add(new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(Aquaculture.MOD_ID, StackHelper.nameFromDescriptionID(f.get().getDescriptionId()))))));
aquaFish.removeIf(p -> p.getItem().equals(AquaItems.JELLYFISH.get()));

Cat.TEMPT_INGREDIENT = StackHelper.mergeIngredient(catBreedingItems, StackHelper.ingredientFromStackList(aquaFish));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
import net.minecraftforge.common.crafting.conditions.IConditionSerializer;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent;

@Mod.EventBusSubscriber(modid = Aquaculture.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ConditionFactory {

@SubscribeEvent
public static void registerConditions(RegisterEvent event) {
CraftingHelper.register(NeptuniumItems.Serializer.INSTANCE);
CraftingHelper.register(NeptuniumArmor.Serializer.INSTANCE);
if (event.getRegistryKey().equals(ForgeRegistries.Keys.RECIPE_SERIALIZERS)) {
CraftingHelper.register(NeptuniumItems.Serializer.INSTANCE);
CraftingHelper.register(NeptuniumArmor.Serializer.INSTANCE);
}
}

public static class NeptuniumItems implements ICondition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static void onTooltip(ItemTooltipEvent event) {
if (!stack.isEmpty()) {
Item item = stack.getItem();
if (stack.is(AquacultureAPI.Tags.TOOLTIP)) {
String itemIdentifier = item.getDescriptionId() + ".tooltip";
String itemIdentifier = StackHelper.nameFromDescriptionID(item.getDescriptionId()) + ".tooltip";
if (InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_LEFT_SHIFT)) {
event.getToolTip().add(Component.translatable(Aquaculture.MOD_ID + "." + itemIdentifier + ".desc").withStyle(ChatFormatting.AQUA));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ public static Ingredient mergeIngredient(Ingredient i1, Ingredient i2) {
public static Ingredient ingredientFromStackList(List<ItemStack> stackList) {
return Ingredient.fromValues(stackList.stream().map(Ingredient.ItemValue::new));
}

public static String nameFromDescriptionID(String descriptionID) {
return descriptionID.replace("item.aquaculture.", "".replace("block.aquaculture.", "")).replace("entity.aquaculture.", "");
}
}

0 comments on commit 87f8a53

Please sign in to comment.