Skip to content

Commit

Permalink
Move to proper lookup for registry names
Browse files Browse the repository at this point in the history
  • Loading branch information
GirafiStudios committed Jun 11, 2022
1 parent f970a22 commit b981f9e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.minecraftforge.client.model.ForgeModelBakery;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

@Mod.EventBusSubscriber(modid = Aquaculture.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
Expand Down Expand Up @@ -65,7 +66,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, StackHelper.nameFromDescriptionID(fish.get().getDescriptionId()).equals("jellyfish")));
event.registerEntityRenderer(fish.get(), (context) -> new AquaFishRenderer(context, ForgeRegistries.ENTITIES.getKey(fish.get()).equals(new ResourceLocation(Aquaculture.MOD_ID, "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 @@ -18,6 +18,8 @@
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -65,9 +67,9 @@ public void render(@Nonnull AquaFishEntity fishEntity, float entityYaw, float pa
@Override
@Nonnull
public ResourceLocation getTextureLocation(@Nonnull AquaFishEntity fishEntity) {
String string = StackHelper.nameFromDescriptionID(fishEntity.getType().getDescriptionId());
if (!string.isEmpty()) {
return new ResourceLocation(Aquaculture.MOD_ID, "textures/entity/fish/" + string + ".png");
ResourceLocation location = ForgeRegistries.ENTITIES.getKey(fishEntity.getType());
if (location != null) {
return new ResourceLocation(Aquaculture.MOD_ID, "textures/entity/fish/" + location.getPath() + ".png");
}
return DEFAULT_LOCATION;
}
Expand Down Expand Up @@ -108,15 +110,17 @@ protected void setupRotations(@Nonnull AquaFishEntity fishEntity, @Nonnull PoseS

@Override
protected void scale(AquaFishEntity fishEntity, @Nonnull PoseStack matrixStack, float partialTickTime) {
String string = StackHelper.nameFromDescriptionID(fishEntity.getType().getDescriptionId());
ResourceLocation location = ForgeRegistries.ENTITIES.getKey(fishEntity.getType());
float scale = 0.0F;
switch (string) {
case "minnow" -> scale = 0.5F;
case "synodontis" -> scale = 0.8F;
case "brown_trout", "piranha" -> scale = 0.9F;
case "pollock" -> scale = 1.1F;
case "atlantic_cod", "blackfish", "catfish", "tambaqui" -> scale = 1.2F;
case "pacific_halibut", "atlantic_halibut", "capitaine", "largemouth_bass", "gar", "arapaima", "tuna" -> scale = 1.4F;
if (location != null) {
switch (location.getPath()) {
case "minnow" -> scale = 0.5F;
case "synodontis" -> scale = 0.8F;
case "brown_trout", "piranha" -> scale = 0.9F;
case "pollock" -> scale = 1.1F;
case "atlantic_cod", "blackfish", "catfish", "tambaqui" -> scale = 1.2F;
case "pacific_halibut", "atlantic_halibut", "capitaine", "largemouth_bass", "gar", "arapaima", "tuna" -> scale = 1.4F;
}
}
if (scale > 0) {
matrixStack.pushPose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nonnull;
import java.math.BigDecimal;
Expand Down Expand Up @@ -60,9 +62,9 @@ public void render(@Nonnull FishMountEntity fishMount, float entityYaw, float pa

matrixStack.pushPose();
matrixStack.translate(-0.5D, -0.5D, -0.5D);
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'
ResourceLocation id = ForgeRegistries.ENTITIES.getKey(fishMount.getType());
if (id != null) {
ModelResourceLocation location = new ModelResourceLocation(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
Expand Up @@ -2,9 +2,7 @@

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 All @@ -29,7 +27,6 @@

import javax.annotation.Nonnull;
import java.util.Objects;
import java.util.Random;

public class AquaFishEntity extends AbstractSchoolingFish {
private final FishType fishType;
Expand Down Expand Up @@ -63,7 +60,7 @@ public ItemStack getPickedResult(HitResult target) {
@Override
@Nonnull
public ItemStack getBucketItemStack() {
return new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(Aquaculture.MOD_ID, StackHelper.nameFromDescriptionID(this.getType().getDescriptionId()) + "_bucket")));
return new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(ForgeRegistries.ENTITIES.getKey(this.getType()).toString() + "_bucket")));
}

@Override
Expand Down Expand Up @@ -99,7 +96,7 @@ public EntityDimensions getDimensions(@Nonnull Pose pose) {
@Override
public void playerTouch(@Nonnull Player player) {
super.playerTouch(player);
if (Objects.equals(StackHelper.nameFromDescriptionID(this.getType().getDescriptionId()), StackHelper.nameFromDescriptionID(AquaItems.JELLYFISH.get().getDescriptionId()))) {
if (Objects.equals(ForgeRegistries.ENTITIES.getKey(this.getType()), new ResourceLocation(Aquaculture.MOD_ID, "jellyfish"))) {
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
Expand Up @@ -41,6 +41,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Objects;

public class FishMountEntity extends HangingEntity implements IEntityAdditionalSpawnData {
private static final Logger PRIVATE_LOGGER = LogManager.getLogger();
Expand Down Expand Up @@ -211,8 +212,8 @@ private void dropItemOrSelf(@Nullable Entity entity, boolean shouldDropSelf) {
}

private Item getItem() {
ResourceLocation location = new ResourceLocation(this.getType().getDescriptionId().replace("entity.", "").replace(".", ":"));
if (ForgeRegistries.ITEMS.containsKey(location)) {
ResourceLocation location = ForgeRegistries.ENTITIES.getKey(this.getType());
if (ForgeRegistries.ITEMS.containsKey(location) && location != null) {
return ForgeRegistries.ITEMS.getValue(location);
}
return Items.AIR;
Expand Down Expand Up @@ -255,7 +256,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().replace("item.", "").replace(".", ":")));
EntityType entityType = ForgeRegistries.ENTITIES.getValue(ForgeRegistries.ITEMS.getKey(displayStack.getItem()));
if (entityType != null && entityType != EntityType.PIG) {
this.entity = entityType.create(this.level);
}
Expand Down Expand Up @@ -305,8 +306,7 @@ public InteractionResult interact(Player player, @Nonnull InteractionHand hand)
if (!this.level.isClientSide) {
if (this.getDisplayedItem().isEmpty()) {
Item heldItem = heldStack.getItem();
String id = heldItem.getDescriptionId().replace("item.", "").replace(".", ":");
EntityType<?> entityType = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(id));
EntityType<?> entityType = ForgeRegistries.ENTITIES.getValue(ForgeRegistries.ITEMS.getKey(heldItem));
if (entityType != EntityType.PIG && AquacultureAPI.FISH_DATA.getFish().contains(heldItem)) {
this.setDisplayedItem(heldStack);
if (!player.getAbilities().instabuild) {
Expand Down Expand Up @@ -342,7 +342,7 @@ protected void setRot(float yaw, float pitch) {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,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(Aquaculture.MOD_ID, StackHelper.nameFromDescriptionID(f.get().getDescriptionId()))))));
fishEntities.forEach(f -> aquaFish.add(new ItemStack(ForgeRegistries.ITEMS.getValue(ForgeRegistries.ENTITIES.getKey(f.get())))));
aquaFish.removeIf(p -> p.getItem().equals(AquaItems.JELLYFISH.get()));

Cat.TEMPT_INGREDIENT = StackHelper.mergeIngredient(catBreedingItems, StackHelper.ingredientFromStackList(aquaFish));
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/com/teammetallurgy/aquaculture/misc/AquaTooltip.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ForgeRegistries;
import org.lwjgl.glfw.GLFW;

@Mod.EventBusSubscriber(modid = Aquaculture.MOD_ID, value = Dist.CLIENT)
Expand All @@ -23,12 +25,15 @@ public static void onTooltip(ItemTooltipEvent event) {
if (!stack.isEmpty()) {
Item item = stack.getItem();
if (stack.is(AquacultureAPI.Tags.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 {
event.getToolTip().add(Component.translatable(Aquaculture.MOD_ID + "." + itemIdentifier + ".title").withStyle(ChatFormatting.AQUA)
.append(" ").append(Component.translatable(Aquaculture.MOD_ID + ".shift").withStyle(ChatFormatting.DARK_GRAY)));
ResourceLocation id = ForgeRegistries.ITEMS.getKey(item);
if (id != null) {
String itemIdentifier = id.getPath() + ".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 {
event.getToolTip().add(Component.translatable(Aquaculture.MOD_ID + "." + itemIdentifier + ".title").withStyle(ChatFormatting.AQUA)
.append(" ").append(Component.translatable(Aquaculture.MOD_ID + ".shift").withStyle(ChatFormatting.DARK_GRAY)));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,4 @@ 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 b981f9e

Please sign in to comment.