Skip to content

Commit

Permalink
Merge branch 'master' into 1.16.1-Trinkets
Browse files Browse the repository at this point in the history
  • Loading branch information
OroArmor committed Jul 26, 2020
2 parents 6487d1b + e82984a commit 835a4ba
Show file tree
Hide file tree
Showing 23 changed files with 367 additions and 9 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ version = project.mod_version
group = project.maven_group

dependencies {
//to change the versions see the gradle.properties file
implementation 'org.jetbrains:annotations:15.0'

//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.8.8+build.202

# Mod Properties
mod_version = 1.1.1
mod_version = beta-1.1.2
maven_group = com.oroarmor
archives_base_name = netherite-plus-mod-trinkets

Expand Down
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Thu Jul 23 21:34:18 PDT 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
8 changes: 8 additions & 0 deletions local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Thu Jul 23 21:07:26 PDT 2020
sdk.dir=C\:\\Users\\Alex Stedman\\AppData\\Local\\Android\\Sdk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
import net.minecraft.util.Identifier;

public class NetheritePlusClientMod implements ClientModInitializer {
public static final SpriteIdentifier NETHERITE_SHIELD_BASE = new SpriteIdentifier(
SpriteAtlasTexture.BLOCK_ATLAS_TEX, new Identifier("netherite_plus", "entity/netherite_shield_base"));

public static final SpriteIdentifier NETHERITE_SHIELD_BASE_NO_PATTERN = new SpriteIdentifier(
SpriteAtlasTexture.BLOCK_ATLAS_TEX,
new Identifier("netherite_plus", "entity/netherite_shield_base_nopattern"));

public static final Identifier SHULKER_BOXES_ATLAS_TEXTURE = new Identifier("netherite_plus",
"textures/atlas/shulker_boxes.png");
Expand All @@ -26,7 +32,9 @@ public void onInitializeClient() {
NetheriteShulkerBoxBlockEntityRenderer::new);

ClientSpriteRegistryCallback.event(SHULKER_BOXES_ATLAS_TEXTURE)
.register(NetheritePlusClientMod::registerSprites);
.register(NetheritePlusClientMod::registerShulkerBoxTextures);
ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEX)
.register(NetheritePlusClientMod::registerShieldTextures);

NetheritePlusModItems.registerItemsAsDamagable();
}
Expand All @@ -47,8 +55,15 @@ private static String makePath(DyeColor color) {
}

@SuppressWarnings("unused")
public static void registerSprites(SpriteAtlasTexture atlas, ClientSpriteRegistryCallback.Registry registry) {
public static void registerShulkerBoxTextures(SpriteAtlasTexture atlas, ClientSpriteRegistryCallback.Registry registry) {
registry.register(new Identifier("netherite_plus", makePath(null)));
Arrays.stream(DyeColor.values()).forEach(c -> registry.register(new Identifier("netherite_plus", makePath(c))));
}

@SuppressWarnings("unused")
public static void registerShieldTextures(SpriteAtlasTexture atlas,
ClientSpriteRegistryCallback.Registry registry) {
registry.register(NETHERITE_SHIELD_BASE.getTextureId());
registry.register(NETHERITE_SHIELD_BASE_NO_PATTERN.getTextureId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.fabricmc.api.ModInitializer;

public class NetheritePlusMod implements ModInitializer {

@Override
public void onInitialize() {
NetheritePlusModItems.registerItems();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Map;

import com.google.common.collect.Maps;
import com.mojang.realmsclient.client.RealmsClient.Environment;
import com.oroarmor.netherite_plus.block.NetheritePlusModBlocks;
import com.oroarmor.util.item.UniqueItemRegistry;

Expand All @@ -17,6 +16,7 @@
import net.minecraft.item.FishingRodItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.Items;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
import net.minecraft.util.registry.Registry;
Expand All @@ -26,9 +26,13 @@ public class NetheritePlusModItems {
public static final Item NETHERITE_ELYTRA = register(new Identifier("netherite_plus", "netherite_elytra"),
new NetheriteElytraItem(new Item.Settings().maxDamage(864).group(ItemGroup.TRANSPORTATION)
.rarity(Rarity.UNCOMMON).fireproof()));

public static final Item NETHERITE_FISHING_ROD = register(new Identifier("netherite_plus", "netherite_fishing_rod"),
new NetheriteFishingRodItem(new Item.Settings().maxDamage(128).group(ItemGroup.TOOLS).fireproof()));

public static final Item NETHERITE_SHIELD = register(new Identifier("netherite_plus", "netherite_shield"),
new NetheriteShieldItem(new Item.Settings().maxDamage(672).group(ItemGroup.COMBAT).fireproof()));

public static final Item.Settings NETHERITE_SHULKER_BOX_ITEM_SETTINGS = new Item.Settings().maxCount(1)
.group(ItemGroup.DECORATIONS).fireproof();

Expand Down Expand Up @@ -70,6 +74,7 @@ public class NetheritePlusModItems {
static {
UniqueItemRegistry.ELYTRA.addItemToRegistry(NETHERITE_ELYTRA);
UniqueItemRegistry.FISHING_ROD.addItemToRegistry(NETHERITE_FISHING_ROD);
UniqueItemRegistry.SHIELD.addItemToRegistry(NETHERITE_SHIELD);
}

public static void registerItems() {
Expand All @@ -82,6 +87,8 @@ public static void registerItemsAsDamagable() {
f.setAccessible(true);
registerElytraAsDamageable(f);
registerFishingRodAsDamageable(f);
// TODO get this working
registerShieldAsDamageable(f);
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -97,6 +104,17 @@ public static void registerElytraAsDamageable(Field f) throws IllegalAccessExcep
});
}

@SuppressWarnings("unchecked")
public static void registerShieldAsDamageable(Field f) throws IllegalAccessException {
((Map<Item, Map<Identifier, ModelPredicateProvider>>) f.get(new Object()))
.computeIfAbsent(NETHERITE_SHIELD, (itemx) -> {
return Maps.newHashMap();
}).put(new Identifier("blocking"), (itemStack, clientWorld, livingEntity) -> {
return livingEntity != null && livingEntity.isUsingItem()
&& livingEntity.getActiveItem() == itemStack ? 1.0F : 0.0F;
});
}

@SuppressWarnings("unchecked")
public static void registerFishingRodAsDamageable(Field f) throws IllegalAccessException {
((Map<Item, Map<Identifier, ModelPredicateProvider>>) f.get(new Object()))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.oroarmor.netherite_plus.item;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ShieldItem;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.UseAction;
import net.minecraft.world.World;

public class NetheriteShieldItem extends ShieldItem {
public NetheriteShieldItem(Settings settings) {
super(settings);
}

@Override
public UseAction getUseAction(ItemStack stack) {
return UseAction.BLOCK;
}

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
ItemStack itemStack = user.getStackInHand(hand);
user.setCurrentHand(hand);
System.out.println("used");
return TypedActionResult.consume(itemStack);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,48 @@

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.mojang.datafixers.util.Pair;
import com.oroarmor.netherite_plus.NetheritePlusClientMod;
import com.oroarmor.netherite_plus.block.NetheriteShulkerBoxBlock;
import com.oroarmor.netherite_plus.block.entity.NetheriteShulkerBoxBlockEntity;
import com.oroarmor.netherite_plus.item.NetheritePlusModItems;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.entity.BannerBlockEntity;
import net.minecraft.block.entity.BannerPattern;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.block.entity.BannerBlockEntityRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.entity.model.ShieldEntityModel;
import net.minecraft.client.render.item.BuiltinModelItemRenderer;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.render.model.ModelLoader;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ShieldItem;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Identifier;

@Environment(EnvType.CLIENT)
@Mixin(BuiltinModelItemRenderer.class)
public class BuiltinModelItemRendererMixin {

private final ShieldEntityModel modelShield = new ShieldEntityModel();
private static final NetheriteShulkerBoxBlockEntity[] RENDER_NETHERITE_SHULKER_BOX_DYED = Arrays
.stream(DyeColor.values()).sorted(Comparator.comparingInt(DyeColor::getId))
.map(NetheriteShulkerBoxBlockEntity::new).toArray((i) -> {
Expand Down Expand Up @@ -55,6 +71,26 @@ public void render(ItemStack stack, ModelTransformation.Mode mode, MatrixStack m

BlockEntityRenderDispatcher.INSTANCE.renderEntity(blockEntity9, matrixStack, vertexConsumerProvider, i, j);
info.cancel();
} else if (item == NetheritePlusModItems.NETHERITE_SHIELD) {
boolean bl = stack.getSubTag("BlockEntityTag") != null;
matrixStack.push();
matrixStack.scale(1.0F, -1.0F, -1.0F);
SpriteIdentifier spriteIdentifier = bl ? NetheritePlusClientMod.NETHERITE_SHIELD_BASE
: NetheritePlusClientMod.NETHERITE_SHIELD_BASE_NO_PATTERN;
VertexConsumer vertexConsumer = spriteIdentifier.getSprite()
.getTextureSpecificVertexConsumer(ItemRenderer.method_29711(vertexConsumerProvider,
this.modelShield.getLayer(spriteIdentifier.getAtlasId()), true, stack.hasGlint()));
this.modelShield.method_23775().render(matrixStack, vertexConsumer, i, j, 1.0F, 1.0F, 1.0F, 1.0F);
if (bl) {
List<Pair<BannerPattern, DyeColor>> list = BannerBlockEntity.method_24280(ShieldItem.getColor(stack),
BannerBlockEntity.getPatternListTag(stack));
BannerBlockEntityRenderer.renderCanvas(matrixStack, vertexConsumerProvider, i, j,
this.modelShield.method_23774(), spriteIdentifier, false, list, stack.hasGlint());
} else {
this.modelShield.method_23774().render(matrixStack, vertexConsumer, i, j, 1.0F, 1.0F, 1.0F, 1.0F);
}

matrixStack.pop();
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.oroarmor.netherite_plus.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import com.oroarmor.util.item.UniqueItemRegistry;

import net.minecraft.client.render.entity.FishingBobberEntityRenderer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

@Mixin(FishingBobberEntityRenderer.class)
public class FishingBobberEntityRendererMixin {

@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;"))
private Item getItem(ItemStack stack) {
return UniqueItemRegistry.FISHING_ROD.getDefaultItem(stack.getItem());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.oroarmor.netherite_plus.mixin;

public class ModelLoaderMixin {
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public abstract class PlayerEntityMixin {
private Item tickMovement(ItemStack stack) {
return UniqueItemRegistry.ELYTRA.getDefaultItem(stack.getItem());
}

@Redirect(method = "damageShield(F)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;"))
private Item shields(ItemStack stack) {
return UniqueItemRegistry.SHIELD.getDefaultItem(stack.getItem());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class NetheritePlusRecipeSerializer {
public static final SpecialRecipeSerializer<NetheriteShulkerBoxColoringRecipe> NETHERITE_SHULKER_BOX = register(
"crafting_special_netheriteshulkerboxcoloring",
new SpecialRecipeSerializer<>(NetheriteShulkerBoxColoringRecipe::new));
public static final SpecialRecipeSerializer<NetheriteShieldDecorationRecipe> NETHERITE_SHIELD = register(
"crafting_special_netheriteshielddecoration",
new SpecialRecipeSerializer<>(NetheriteShieldDecorationRecipe::new));

public static <S extends RecipeSerializer<T>, T extends Recipe<?>> S register(String id, S serializer) {
return Registry.register(Registry.RECIPE_SERIALIZER, new Identifier("netherite_plus", id), serializer);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.oroarmor.netherite_plus.recipe;

import com.oroarmor.netherite_plus.item.NetheritePlusModItems;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.BannerItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.recipe.SpecialCraftingRecipe;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;

public class NetheriteShieldDecorationRecipe extends SpecialCraftingRecipe {
public NetheriteShieldDecorationRecipe(Identifier identifier) {
super(identifier);
}

@Override
public boolean matches(CraftingInventory craftingInventory, World world) {
ItemStack itemStack = ItemStack.EMPTY;
ItemStack itemStack2 = ItemStack.EMPTY;

for (int i = 0; i < craftingInventory.size(); ++i) {
ItemStack itemStack3 = craftingInventory.getStack(i);
if (!itemStack3.isEmpty()) {
if (itemStack3.getItem() instanceof BannerItem) {
if (!itemStack2.isEmpty()) {
return false;
}

itemStack2 = itemStack3;
} else {
if (itemStack3.getItem() != NetheritePlusModItems.NETHERITE_SHIELD) {
return false;
}

if (!itemStack.isEmpty()) {
return false;
}

if (itemStack3.getSubTag("BlockEntityTag") != null) {
return false;
}

itemStack = itemStack3;
}
}
}

if (!itemStack.isEmpty() && !itemStack2.isEmpty()) {
return true;
}
return false;

}

@Override
public ItemStack craft(CraftingInventory craftingInventory) {
ItemStack itemStack = ItemStack.EMPTY;
ItemStack itemStack2 = ItemStack.EMPTY;

for (int i = 0; i < craftingInventory.size(); ++i) {
ItemStack itemStack3 = craftingInventory.getStack(i);
if (!itemStack3.isEmpty()) {
if (itemStack3.getItem() instanceof BannerItem) {
itemStack = itemStack3;
} else if (itemStack3.getItem() == NetheritePlusModItems.NETHERITE_SHIELD) {
itemStack2 = itemStack3.copy();
}
}
}

if (itemStack2.isEmpty()) {
return itemStack2;
}
CompoundTag compoundTag = itemStack.getSubTag("BlockEntityTag");
CompoundTag compoundTag2 = compoundTag == null ? new CompoundTag() : compoundTag.copy();
compoundTag2.putInt("Base", ((BannerItem) itemStack.getItem()).getColor().getId());
itemStack2.putSubTag("BlockEntityTag", compoundTag2);
return itemStack2;
}

@Override
@Environment(EnvType.CLIENT)
public boolean fits(int width, int height) {
return width * height >= 2;
}

@Override
public RecipeSerializer<?> getSerializer() {
return RecipeSerializer.SHIELD_DECORATION;
}
}
Loading

0 comments on commit 835a4ba

Please sign in to comment.