Skip to content

Commit

Permalink
dont create a registry holder for the item filter when its not going …
Browse files Browse the repository at this point in the history
…to be registered, closes #7
  • Loading branch information
gliscowo committed Mar 19, 2022
1 parent d09cce6 commit ad4fb65
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ minecraft_version=1.18.2
yarn_mappings=1.18.2+build.1
loader_version=0.13.3
# Mod Properties
mod_version=0.1.9
mod_version=0.1.10
maven_group=com.glisco
archives_base_name=interactic
# Dependencies
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/interactic/InteracticInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class InteracticInit implements ModInitializer {

public static final String MOD_ID = "interactic";

public static final Item ITEM_FILTER = new ItemFilterItem();
private static Item ITEM_FILTER = null;

private static InteracticConfig CONFIG;
private static float itemRotationSpeedMultiplier = 1f;
Expand All @@ -39,7 +39,7 @@ public void onInitialize() {
if (FabricLoader.getInstance().isModLoaded("iris")) itemRotationSpeedMultiplier = 0.5f;

if (CONFIG.itemFilterEnabled) {
Registry.register(Registry.ITEM, new Identifier(MOD_ID, "item_filter"), ITEM_FILTER);
ITEM_FILTER = Registry.register(Registry.ITEM, new Identifier(MOD_ID, "item_filter"), new ItemFilterItem());

ServerPlayNetworking.registerGlobalReceiver(new Identifier(MOD_ID, "filter_mode_request"), (server, player, handler, buf, responseSender) -> {
final boolean newMode = buf.readBoolean();
Expand Down Expand Up @@ -76,6 +76,10 @@ public void onInitialize() {
}
}

public static Item getItemFilter() {
return ITEM_FILTER;
}

private void dropSelected(PlayerEntity player, boolean dropAll) {
player.dropItem(player.getInventory().removeStack(player.getInventory().selectedSlot, dropAll && !player.getInventory().getMainHandStack().isEmpty() ? player.getInventory().getMainHandStack().getCount() : 1), false, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void onConstructor(EntityRendererFactory.Context context, CallbackInfo c
this.shadowRadius = 0;
}

@Inject(at = @At("HEAD"), method = "render", cancellable = true)
@Inject(at = @At("HEAD"), method = "render(Lnet/minecraft/entity/ItemEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", cancellable = true)
private void render(ItemEntity entity, float f, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, int light, CallbackInfo callback) {
if (!InteracticInit.getConfig().fancyItemRendering) return;

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/interactic/util/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.Vec3d;

import java.util.Collection;
Expand Down Expand Up @@ -43,7 +42,7 @@ public static boolean canPlayerPickUpItem(PlayerEntity player, ItemStack stack)
if (!InteracticInit.getConfig().autoPickup) return false;
if (!InteracticInit.getConfig().itemFilterEnabled) return true;

var filterOptional = ((PlayerInventoryAccessor) player.getInventory()).getCombinedInventory().stream().flatMap(Collection::stream).filter(itemStack -> itemStack.isOf(InteracticInit.ITEM_FILTER)).findFirst();
var filterOptional = ((PlayerInventoryAccessor) player.getInventory()).getCombinedInventory().stream().flatMap(Collection::stream).filter(itemStack -> itemStack.isOf(InteracticInit.getItemFilter())).findFirst();
if (filterOptional.isEmpty()) return true;

final ItemStack filterStack = filterOptional.get();
Expand Down

0 comments on commit ad4fb65

Please sign in to comment.