Skip to content

Commit

Permalink
Fixed server not launching
Browse files Browse the repository at this point in the history
  • Loading branch information
Insane96 committed Jul 31, 2022
1 parent 3ac1e07 commit b4a9485
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 64 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/insane96mcp/shieldsplus/item/SPShieldItem.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package com.insane96mcp.shieldsplus.item;

import com.insane96mcp.shieldsplus.ShieldsPlus;
import com.insane96mcp.shieldsplus.render.ShieldBlockEntityWithoutLevelRenderer;
import com.insane96mcp.shieldsplus.setup.Strings;
import net.minecraft.ChatFormatting;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.client.resources.model.Material;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ShieldItem;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.IItemRenderProperties;
import org.jetbrains.annotations.Nullable;

Expand All @@ -23,6 +28,11 @@ public class SPShieldItem extends ShieldItem {
public static final ResourceLocation BLOCKING = new ResourceLocation("minecraft:blocking");
public final SPShieldMaterial material;

@OnlyIn(Dist.CLIENT)
public Material clientMaterial;
@OnlyIn(Dist.CLIENT)
public Material clientMaterialNoPattern;

public SPShieldItem(SPShieldMaterial material, Properties p_43089_) {
super(p_43089_);
this.material = material;
Expand Down Expand Up @@ -52,4 +62,10 @@ public void appendHoverText(ItemStack itemStack, @Nullable Level level, List<Com
public static void addDamageBlockedText(List<Component> components, double blockedDamage) {
components.add(new TranslatableComponent(Strings.Translatable.DAMAGE_BLOCKED, new DecimalFormat("#.#").format(blockedDamage)).withStyle(ChatFormatting.BLUE));
}

@OnlyIn(Dist.CLIENT)
public void initClientMaterial() {
this.clientMaterial = new Material(InventoryMenu.BLOCK_ATLAS, new ResourceLocation(ShieldsPlus.MOD_ID, "entity/%s_shield".formatted(this.material.materialName)));
this.clientMaterialNoPattern = new Material(InventoryMenu.BLOCK_ATLAS, new ResourceLocation(ShieldsPlus.MOD_ID, "entity/%s_shield_nopattern".formatted(this.material.materialName)));
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package com.insane96mcp.shieldsplus.item;

import com.insane96mcp.shieldsplus.ShieldsPlus;
import net.minecraft.client.resources.model.Material;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.Rarity;

public class SPShieldMaterial {
public Material material;
public Material noPatternMaterial;
//public Material material;
//public Material noPatternMaterial;
public String materialName;
public double damageBlocked;
public int durability;
public Rarity rarity;

public SPShieldMaterial(String material, double damageBlocked, int durability, Rarity rarity) {
this.material = new Material(InventoryMenu.BLOCK_ATLAS, new ResourceLocation(ShieldsPlus.MOD_ID, "entity/%s_shield".formatted(material)));
this.noPatternMaterial = new Material(InventoryMenu.BLOCK_ATLAS, new ResourceLocation(ShieldsPlus.MOD_ID, "entity/%s_shield_nopattern".formatted(material)));
public SPShieldMaterial(String materialName, double damageBlocked, int durability, Rarity rarity) {
//this.material = new Material(InventoryMenu.BLOCK_ATLAS, new ResourceLocation(ShieldsPlus.MOD_ID, "entity/%s_shield".formatted(material)));
//this.noPatternMaterial = new Material(InventoryMenu.BLOCK_ATLAS, new ResourceLocation(ShieldsPlus.MOD_ID, "entity/%s_shield_nopattern".formatted(material)));
this.materialName = materialName;
this.damageBlocked = damageBlocked;
this.durability = durability;
this.rarity = rarity;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void renderByItem(ItemStack itemStack, ItemTransforms.TransformType trans
poseStack.scale(1.0F, -1.0F, -1.0F);
Material material = hasBanner ? ModelBakery.SHIELD_BASE : ModelBakery.NO_PATTERN_SHIELD;
if (itemStack.getItem() instanceof SPShieldItem spShieldItem) {
material = hasBanner ? spShieldItem.material.material : spShieldItem.material.noPatternMaterial;
material = hasBanner ? spShieldItem.clientMaterial : spShieldItem.clientMaterialNoPattern;
}
VertexConsumer vertexconsumer = material.sprite().wrap(ItemRenderer.getFoilBufferDirect(multiBufferSource, this.shieldModel.renderType(material.atlasLocation()), true, itemStack.hasFoil()));
this.shieldModel.handle().render(poseStack, vertexconsumer, p_108834_, p_108835_, 1.0F, 1.0F, 1.0F, 1.0F);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/insane96mcp/shieldsplus/setup/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public static void setup(final FMLClientSetupEvent event) {
@SubscribeEvent
public static void onStitch(TextureStitchEvent.Pre event) {
for (RegistryObject<SPShieldItem> shieldItem : SPItems.SHIELDS) {
event.addSprite(shieldItem.get().material.material.texture());
event.addSprite(shieldItem.get().material.noPatternMaterial.texture());
shieldItem.get().initClientMaterial();
event.addSprite(shieldItem.get().clientMaterial.texture());
event.addSprite(shieldItem.get().clientMaterialNoPattern.texture());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SPItems {

public static RegistryObject<SPShieldItem> registerShield(String id, SPShieldMaterial material) {
RegistryObject<SPShieldItem> shield = ITEMS.register(id, () -> new SPShieldItem(material, new Item.Properties().durability(material.durability).tab(CreativeModeTab.TAB_COMBAT).rarity(material.rarity)));
SHIELDS.add(shield); // Will surely not work
SHIELDS.add(shield);
return shield;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public class SPShieldMaterials {
public static final SPShieldMaterial GOLDEN = new SPShieldMaterial("golden", 1, 42, Rarity.COMMON);
public static final SPShieldMaterial IRON = new SPShieldMaterial("iron", 5, 332, Rarity.COMMON);
public static final SPShieldMaterial DIAMOND = new SPShieldMaterial("diamond", 7, 588, Rarity.COMMON);
public static final SPShieldMaterial NETHERITE = new SPShieldMaterial("netherite", 8, 672, Rarity.RARE);
public static final SPShieldMaterial NETHERITE = new SPShieldMaterial("netherite", 8, 672, Rarity.COMMON);
}

0 comments on commit b4a9485

Please sign in to comment.