-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix copycat doors not being placed correctly by schematics
- Loading branch information
Showing
7 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
common/src/main/java/com/copycatsplus/copycats/mixin/copycat/door/BlockHelperMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.copycatsplus.copycats.mixin.copycat.door; | ||
|
||
import com.simibubi.create.foundation.utility.BlockHelper; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
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; | ||
|
||
/** | ||
* Fix a hidden bug in Create which causes a crash due to missing ID when merging block entities in schematic printing. | ||
*/ | ||
@Mixin(BlockHelper.class) | ||
public class BlockHelperMixin { | ||
@Inject( | ||
method = "placeSchematicBlock", | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/BlockEntity;loadStatic(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/world/level/block/entity/BlockEntity;") | ||
) | ||
private static void placeSchematicBlock(Level world, BlockState state, BlockPos target, ItemStack stack, CompoundTag data, CallbackInfo ci) { | ||
BlockEntity existingBlockEntity = world.getBlockEntity(target); | ||
if (existingBlockEntity != null && existingBlockEntity.getBlockState().getBlock().equals(state.getBlock())) { | ||
ResourceLocation resourceLocation = BlockEntityType.getKey(existingBlockEntity.getType()); | ||
assert resourceLocation != null; | ||
data.putString("id", resourceLocation.toString()); | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...ain/java/com/copycatsplus/copycats/mixin/copycat/door/SchematicannonBlockEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.copycatsplus.copycats.mixin.copycat.door; | ||
|
||
import com.copycatsplus.copycats.foundation.copycat.ICopycatBlock; | ||
import com.copycatsplus.copycats.foundation.copycat.ICopycatBlockEntity; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.simibubi.create.content.schematics.cannon.SchematicannonBlockEntity; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf; | ||
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.CallbackInfoReturnable; | ||
|
||
import static net.minecraft.world.level.block.state.properties.BlockStateProperties.DOUBLE_BLOCK_HALF; | ||
|
||
/** | ||
* Force the schematicannon to place both the upper and lower halves of copycat doors | ||
*/ | ||
@Mixin(SchematicannonBlockEntity.class) | ||
public class SchematicannonBlockEntityMixin { | ||
@Inject( | ||
method = "shouldIgnoreBlockState", | ||
at = @At("RETURN"), | ||
cancellable = true | ||
) | ||
private void shouldIgnoreBlockStateMixin(BlockState state, BlockEntity be, CallbackInfoReturnable<Boolean> cir) { | ||
if (state.hasProperty(DOUBLE_BLOCK_HALF) && be instanceof ICopycatBlockEntity) { | ||
cir.setReturnValue(false); | ||
} | ||
} | ||
|
||
/** | ||
* Make an exception for the "protect block entities" setting so that the upper half of a copycat door can be placed | ||
*/ | ||
@WrapOperation( | ||
method = "shouldPlace", | ||
at = @At(value = "FIELD", target = "Lcom/simibubi/create/content/schematics/cannon/SchematicannonBlockEntity;replaceBlockEntities:Z") | ||
) | ||
private boolean shouldPlace(SchematicannonBlockEntity instance, Operation<Boolean> original, BlockPos pos, BlockState state, BlockEntity be, BlockState toReplace, | ||
BlockState toReplaceOther, boolean isNormalCube) { | ||
boolean originalReplace = original.call(instance); | ||
return originalReplace || (state.getBlock() instanceof ICopycatBlock && state.hasProperty(DOUBLE_BLOCK_HALF) && state.getValue(DOUBLE_BLOCK_HALF) == DoubleBlockHalf.UPPER); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...src/main/java/com/copycatsplus/copycats/mixin/foundation/copycat/BlockEntityAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.copycatsplus.copycats.mixin.foundation.copycat; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(BlockEntity.class) | ||
public interface BlockEntityAccessor { | ||
@Invoker | ||
void callSaveMetadata(CompoundTag tag); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters