Skip to content

Commit

Permalink
Fix armor checks triggering for non-armor equipment
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Mar 25, 2023
1 parent b8bf673 commit 749c021
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fabric_version=0.74.2+1.19.4

maven_group = eu.pb4

mod_version = 0.4.1
mod_version = 0.4.2

minecraft_version_supported = ">=1.19.4-"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ public abstract class ServerPlayNetworkHandlerMixin {

if (itemStack.getItem() instanceof PolymerItem polymerItem) {
var data = PolymerItemUtils.getItemSafely(polymerItem, itemStack, this.player);
if (data.item() instanceof Equipment) {
if (data.item() instanceof Equipment equipment && equipment.getSlotType().isArmorSlot()) {
this.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(this.player.playerScreenHandler.syncId, this.player.playerScreenHandler.nextRevision(), packet.getHand() == Hand.MAIN_HAND ? 36 + this.player.getInventory().selectedSlot : 45, itemStack));

var slot = MobEntity.getPreferredEquipmentSlot(new ItemStack(data.item()));
this.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(this.player.playerScreenHandler.syncId, this.player.playerScreenHandler.nextRevision(), 8 - slot.getEntitySlotId(), this.player.getEquippedStack(slot)));
this.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(this.player.playerScreenHandler.syncId, this.player.playerScreenHandler.nextRevision(), 8 - equipment.getSlotType().getEntitySlotId(), this.player.getEquippedStack(equipment.getSlotType())));
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions polymer-core/src/testmod/java/eu/pb4/polymertest/BuggedItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package eu.pb4.polymertest;

import eu.pb4.polymer.core.api.item.PolymerItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.server.network.ServerPlayerEntity;
import org.jetbrains.annotations.Nullable;


public class BuggedItem extends Item implements PolymerItem {

public BuggedItem(Settings settings) {
super(settings);
}

@Override
public Item getPolymerItem(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
//if(!PolymerResourcePackUtils.hasPack(player)) return vanillaItem;
return Items.SHIELD;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void accept(ItemGroup.DisplayContext arg, ItemGroup.Entries entries) {
public static BlockItem TATER_BLOCK_ITEM = new PolymerHeadBlockItem(TATER_BLOCK, new Item.Settings());
public static BlockItem TATER_BLOCK_ITEM2 = new PolymerBlockItem(TATER_BLOCK, new Item.Settings(), Items.RAW_IRON_BLOCK);
public static TestPickaxeItem PICKAXE = new TestPickaxeItem(Items.WOODEN_PICKAXE, ToolMaterials.NETHERITE, 10, -3.9f, new Item.Settings());
public static TestPickaxeItem PICKAXE2 = new TestPickaxeItem(Items.NETHERITE_PICKAXE, ToolMaterials.WOOD, 10, -3.9f, new Item.Settings());
public static TestPickaxeItem PICKAXE2 = new TestPickaxeItem(Items.NETHERITE_PICKAXE, ToolMaterials.WOOD, 10, -5f, new Item.Settings());
public static TestHelmetItem HELMET = new TestHelmetItem(new Item.Settings());
public static Block WRAPPED_BLOCK = new SimplePolymerBlock(AbstractBlock.Settings.copy(BLOCK), BLOCK);
public static Block SELF_REFERENCE_BLOCK = new SelfReferenceBlock(AbstractBlock.Settings.copy(Blocks.STONE));
Expand Down Expand Up @@ -191,6 +191,8 @@ public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity
player.networkHandler.sendPacket(new PlayerAbilitiesS2CPacket(player.getAbilities()));
});



public static SimplePolymerItem MARKER_TEST = new ClickItem(new Item.Settings(), Items.BLAZE_ROD, (player, hand) -> {
if (hand == Hand.OFF_HAND) {
DebugInfoSender.clearGameTestMarkers((ServerWorld) player.getWorld());
Expand Down Expand Up @@ -225,6 +227,7 @@ public void onInitialize() {
PolymerResourcePackUtils.getInstance().setPackDescription(Text.literal("TEST REPLACED DESCRIPTION").formatted(Formatting.GREEN));
//PolymerResourcePackUtils.markAsRequired();
//PolymerResourcePackUtils.addModAsAssetsSource("promenade");
register(Registries.ITEM, new Identifier("bugged", "wooden_sword"), new BuggedItem(new Item.Settings()));

register(Registries.ITEM, new Identifier("test", "item"), ITEM);
register(Registries.ITEM, new Identifier("test", "item2"), ITEM_2);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package eu.pb4.polymertest.mixin;

import net.minecraft.block.RedstoneLampBlock;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(RedstoneLampBlock.class)
public class RedstoneLampMixin {
@ModifyConstant(method = "neighborUpdate", constant = @Constant(intValue = 4))
private int fastLamps(int i) {
return 1;
}
}
1 change: 1 addition & 0 deletions polymer-core/src/testmod/resources/test.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"DisplayEntityAccessor",
"EntityAccessor",
"ItemDisplayEntityAccessor",
"RedstoneLampMixin",
"RideCommandMixin",
"ServerPlayNetworkHandlerMixin",
"VillagerEntityAccessor"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.pb4.polymer.virtualentity.api.elements;

import eu.pb4.polymer.virtualentity.api.tracker.DisplayTrackedData;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.decoration.Brightness;
import net.minecraft.entity.decoration.DisplayEntity;
Expand All @@ -10,6 +11,7 @@
import org.joml.*;


@SuppressWarnings("ConstantConditions")
public abstract class DisplayElement extends GenericEntityElement {
@Override
protected abstract EntityType<? extends DisplayEntity> getEntityType();
Expand Down Expand Up @@ -136,6 +138,10 @@ public float getDisplayWidth() {
return this.dataTracker.get(DisplayTrackedData.WIDTH);
}

public float getDisplayHeight() {
return this.dataTracker.get(DisplayTrackedData.HEIGHT);
}

public void setDisplayWidth(float width) {
this.dataTracker.set(DisplayTrackedData.WIDTH, width);
}
Expand All @@ -144,6 +150,16 @@ public void setDisplayHeight(float height) {
this.dataTracker.set(DisplayTrackedData.HEIGHT, height);
}

public void setDisplaySize(float width, float height) {
this.setDisplayWidth(width);
this.setDisplayHeight(height);
}

public void setDisplaySize(EntityDimensions dimensions) {
this.setDisplayWidth(dimensions.width);
this.setDisplayHeight(dimensions.height);
}

public int getGlowColorOverride() {
return this.dataTracker.get(DisplayTrackedData.GLOW_COLOR_OVERRIDE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import eu.pb4.polymer.virtualentity.api.tracker.InteractionTrackedData;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -77,6 +78,11 @@ public void setSize(float width, float height) {
setHeight(height);
}

public void setSize(EntityDimensions dimensions) {
setWidth(dimensions.width);
setHeight(dimensions.height);
}

public boolean shouldRespond() {
return this.dataTracker.get(InteractionTrackedData.RESPONSE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class ServerPlayNetworkHandlerMixin implements HolderHolder {
var i = x.getInteraction(id, this.player);
if (i != null) {
packet.handle(new PacketInterHandler(this.player, i));
break;
}
}
}
Expand Down

0 comments on commit 749c021

Please sign in to comment.