Skip to content

Commit

Permalink
Merge pull request #139 from K0LALA/1.20.1
Browse files Browse the repository at this point in the history
Fixed wearing a brute/zombified piglin head causes the game to crash
  • Loading branch information
AlphaMode authored Jul 16, 2024
2 parents dbb6525 + 9987cc3 commit 16dba0a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@ public InteractionResult interactLivingEntity(ItemStack stack, Player playerIn,
// is the chest slot empty?
ItemStack chestArmor = playerIn.getItemBySlot(EquipmentSlot.CHEST);

// need enough space to exchange the chest armor
if (chestArmor.getItem() != this && playerIn.getInventory().getFreeSlot() == -1) {
// not enough inventory space
return InteractionResult.PASS;
if(chestArmor != ItemStack.EMPTY) {
// need enough space to exchange the chest armor
if (chestArmor.getItem() != this && playerIn.getInventory().getFreeSlot() == -1) {
// not enough inventory space
return InteractionResult.PASS;
}
}

// try carrying the entity
if (this.pickupEntity(playerIn, target)) {
// unequip old armor
if (chestArmor.getItem() != this) {
ItemHandlerHelper.giveItemToPlayer(playerIn, chestArmor);
int piggyBackpackSlot = playerIn.getInventory().findSlotMatchingItem(stack);
playerIn.getInventory().add(piggyBackpackSlot, chestArmor);
chestArmor = ItemStack.EMPTY;
}

Expand Down
35 changes: 35 additions & 0 deletions src/main/java/slimeknights/tconstruct/mixin/SkullBlockMixins.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package slimeknights.tconstruct.mixin;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.AbstractSkullBlock;
import net.minecraft.world.level.block.SkullBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import slimeknights.tconstruct.world.TinkerHeadType;

@Mixin(SkullBlock.class)
public class SkullBlockMixins extends AbstractSkullBlock {

@Shadow
@Final
protected static VoxelShape PIGLIN_SHAPE;

public SkullBlockMixins(SkullBlock.Type type, Properties properties) {
super(type, properties);
}

@Inject(method = "getShape", at = @At("TAIL"), cancellable = true)
private void getCustomShape(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, CollisionContext collisionContext, CallbackInfoReturnable<VoxelShape> cir) {
if (this.getType() == TinkerHeadType.PIGLIN_BRUTE || this.getType() == TinkerHeadType.ZOMBIFIED_PIGLIN) {
cir.setReturnValue(PIGLIN_SHAPE);
}
}
}
5 changes: 1 addition & 4 deletions src/main/java/slimeknights/tconstruct/world/TinkerWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private static Function<WoodVariant,BlockBehaviour.Properties> createSlimewood(M
public static final ResourceKey<PlacedFeature> placedEarthGeodeKey = placed("earth_geode");
// sky
public static final GeodeItemObject skyGeode = BLOCKS.registerGeode("sky_slime_crystal", MapColor.COLOR_BLUE, Sounds.SKY_CRYSTAL, Sounds.SKY_CRYSTAL_CHIME.getSound(), Sounds.SKY_CRYSTAL_CLUSTER, 0, WORLD_PROPS);
public static final ResourceKey<ConfiguredFeature<?,?>> configuredSkyGeodeKey = configured("sky_geode");;
public static final ResourceKey<ConfiguredFeature<?,?>> configuredSkyGeodeKey = configured("sky_geode");
public static final ResourceKey<PlacedFeature> placedSkyGeodeKey = placed("sky_geode");
// ichor
public static final GeodeItemObject ichorGeode = BLOCKS.registerGeode("ichor_slime_crystal", MapColor.COLOR_ORANGE, Sounds.ICHOR_CRYSTAL, Sounds.ICHOR_CRYSTAL_CHIME.getSound(), Sounds.ICHOR_CRYSTAL_CLUSTER, 10, WORLD_PROPS);
Expand Down Expand Up @@ -466,9 +466,6 @@ public static void gatherData(final FabricDataGenerator.Pack pack) {
/** Creates a skull block for the given head type */
private static SkullBlock makeHead(TinkerHeadType type) {
BlockBehaviour.Properties props = BlockBehaviour.Properties.of().pushReaction(PushReaction.DESTROY).strength(1.0F);
if (type == TinkerHeadType.PIGLIN_BRUTE || type == TinkerHeadType.ZOMBIFIED_PIGLIN) {
return new SkullBlock(SkullBlock.Types.PIGLIN, props);
}
return new SkullBlock(type, props);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/hephaestus.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"maxShiftBy": 5
},
"mixins": [
"DataFixersMixin"
"DataFixersMixin",
"SkullBlockMixins"
]
}

0 comments on commit 16dba0a

Please sign in to comment.