diff --git a/common/src/main/java/com/sudolev/interiors/Utils.java b/common/src/main/java/com/sudolev/interiors/Utils.java index c58ac44..0973090 100644 --- a/common/src/main/java/com/sudolev/interiors/Utils.java +++ b/common/src/main/java/com/sudolev/interiors/Utils.java @@ -1,5 +1,7 @@ package com.sudolev.interiors; +import dev.architectury.injectables.annotations.ExpectPlatform; + import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraft.tags.TagKey; @@ -11,8 +13,6 @@ import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; -import dev.architectury.injectables.annotations.ExpectPlatform; - public abstract class Utils { @ExpectPlatform public static String getVersion(String modid) { diff --git a/common/src/main/java/com/sudolev/interiors/content/block/chair/BigChairBlock.java b/common/src/main/java/com/sudolev/interiors/content/block/chair/BigChairBlock.java index 7a35d56..0683dc2 100644 --- a/common/src/main/java/com/sudolev/interiors/content/block/chair/BigChairBlock.java +++ b/common/src/main/java/com/sudolev/interiors/content/block/chair/BigChairBlock.java @@ -1,32 +1,10 @@ package com.sudolev.interiors.content.block.chair; -import java.util.List; - -import org.jetbrains.annotations.NotNull; - -import com.simibubi.create.AllItems; -import com.simibubi.create.foundation.utility.BlockHelper; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.TamableAnimal; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DyeColor; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; -import com.sudolev.interiors.Utils; -import com.sudolev.interiors.content.entity.BigSeatEntity; -import com.sudolev.interiors.content.registry.CIBlocks; - public class BigChairBlock extends ChairBlock { private static final VoxelShape SHAPE = Shapes.or(Block.box(0, 5, 0, 16, 13, 16), Block.box(0, 0, 4, 16, 5, 12)); @@ -38,50 +16,4 @@ public BigChairBlock(Properties properties, DyeColor color) { public VoxelShape shape() { return SHAPE; } - - public static void sitDown(@NotNull Level world, @NotNull BlockPos pos, @NotNull Entity entity) { - if(world.isClientSide) return; - BigSeatEntity seat = new BigSeatEntity(world, pos); - seat.setPos(pos.getX() + .5f, pos.getY() + .34f, pos.getZ() + .5f); - world.addFreshEntity(seat); - entity.startRiding(seat, true); - if(entity instanceof TamableAnimal ta) - ta.setInSittingPose(true); - } - - @Override - public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult result) { - ItemStack heldItem = player.getItemInHand(hand); - - if(heldItem == AllItems.WRENCH.asStack(1) - || heldItem.is(AllItems.WRENCH.get())) { - return InteractionResult.PASS; - } - - DyeColor color = Utils.colorFromItem(heldItem); - - if(color != null && color != this.color) { - if(world.isClientSide) return InteractionResult.SUCCESS; - BlockState newState = BlockHelper.copyProperties(state, CIBlocks.CHAIRS.get(color).getDefaultState()); - world.setBlockAndUpdate(pos, newState); - return InteractionResult.SUCCESS; - } - - List seats = world.getEntitiesOfClass(BigSeatEntity.class, new AABB(pos)); - if(!seats.isEmpty()) { - BigSeatEntity entity = seats.get(0); - List passengers = entity.getPassengers(); - if(!passengers.isEmpty() && passengers.get(0) instanceof Player) return InteractionResult.PASS; - if(!world.isClientSide) { - entity.ejectPassengers(); - player.startRiding(entity); - } - return InteractionResult.SUCCESS; - } - - if(!world.isClientSide) { - sitDown(world, pos, getLeashed(world, player).or(player)); - } - return InteractionResult.SUCCESS; - } } \ No newline at end of file diff --git a/common/src/main/java/com/sudolev/interiors/foundation/mixin/SeatBlockMixin.java b/common/src/main/java/com/sudolev/interiors/foundation/mixin/SeatBlockMixin.java index efe2ebe..ed1374b 100644 --- a/common/src/main/java/com/sudolev/interiors/foundation/mixin/SeatBlockMixin.java +++ b/common/src/main/java/com/sudolev/interiors/foundation/mixin/SeatBlockMixin.java @@ -2,22 +2,29 @@ import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.DyeColor; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; import com.simibubi.create.content.contraptions.actors.seat.SeatBlock; import com.simibubi.create.content.contraptions.actors.seat.SeatEntity; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.sugar.Local; import com.sudolev.interiors.content.block.chair.BigChairBlock; +import com.sudolev.interiors.content.block.chair.FloorChairBlock; import com.sudolev.interiors.content.entity.BigSeatEntity; +import com.sudolev.interiors.content.registry.CIBlocks; + +import com.tterrag.registrate.util.entry.BlockEntry; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At.Shift; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -25,16 +32,16 @@ public abstract class SeatBlockMixin { @Inject(method = "isSeatOccupied", at = @At("HEAD"), cancellable = true) - private static void weCountAsSeatsToo(Level world, BlockPos pos, CallbackInfoReturnable cir) { - if(!world.getEntitiesOfClass(BigSeatEntity.class, new AABB(pos)).isEmpty()) + private static void weCountAsSeatsToo(Level level, BlockPos pos, CallbackInfoReturnable cir) { + if(!level.getEntitiesOfClass(BigSeatEntity.class, new AABB(pos)).isEmpty()) cir.setReturnValue(true); } - @Redirect(method = "sitDown", at = @At(value = "NEW", target = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Lcom/simibubi/create/content/contraptions/actors/seat/SeatEntity;")) - private static SeatEntity createCorrectSeatEntity(Level world, BlockPos pos) { - return world.getBlockState(pos).getBlock() instanceof BigChairBlock - ? new BigSeatEntity(world, pos) - : new SeatEntity(world, pos); + @ModifyExpressionValue(method = "sitDown", at = @At(value = "NEW", target = "(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Lcom/simibubi/create/content/contraptions/actors/seat/SeatEntity;")) + private static SeatEntity createCorrectSeatEntity(SeatEntity original, @Local(argsOnly = true) Level level, @Local(argsOnly = true) BlockPos pos) { + return level.getBlockState(pos).getBlock() instanceof BigChairBlock + ? new BigSeatEntity(level, pos) + : new SeatEntity(level, pos); } @Inject(method = "sitDown", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z", shift = Shift.BEFORE)) @@ -43,4 +50,17 @@ private static void getFixedY(Level world, BlockPos pos, Entity entity, Callback seat.setPos(seat.getX(), seat.getY() + .34f, seat.getZ()); } } + + @ModifyExpressionValue(method = "use", at = @At(value = "INVOKE", target = "Lcom/simibubi/create/foundation/block/DyedBlockList;get(Lnet/minecraft/world/item/DyeColor;)Lcom/tterrag/registrate/util/entry/BlockEntry;")) + private BlockEntry useBigChairSeats(BlockEntry original, @Local(argsOnly = true) BlockState state, @Local DyeColor color) { + SeatBlock thiz = (SeatBlock) (Object) this; + + if(thiz instanceof BigChairBlock) { + return thiz == CIBlocks.KELP_CHAIR.get() ? CIBlocks.KELP_CHAIR : CIBlocks.CHAIRS.get(color); + } else if(thiz instanceof FloorChairBlock) { + return thiz == CIBlocks.KELP_FLOOR_CHAIR.get() ? CIBlocks.KELP_FLOOR_CHAIR : CIBlocks.FLOOR_CHAIRS.get(color); + } else { + return thiz == CIBlocks.KELP_SEAT.get() ? CIBlocks.KELP_SEAT : original; + } + } } diff --git a/fabric/src/main/java/com/sudolev/interiors/fabric/CreateInteriorsFabric.java b/fabric/src/main/java/com/sudolev/interiors/fabric/CreateInteriorsFabric.java index f314e69..13ea660 100644 --- a/fabric/src/main/java/com/sudolev/interiors/fabric/CreateInteriorsFabric.java +++ b/fabric/src/main/java/com/sudolev/interiors/fabric/CreateInteriorsFabric.java @@ -3,7 +3,6 @@ import net.fabricmc.api.ModInitializer; import com.sudolev.interiors.CreateInteriors; - public class CreateInteriorsFabric implements ModInitializer { @Override diff --git a/forge/src/main/java/com/sudolev/interiors/forge/CreateInteriorsForge.java b/forge/src/main/java/com/sudolev/interiors/forge/CreateInteriorsForge.java index 5bd5c0d..3e6f1d6 100644 --- a/forge/src/main/java/com/sudolev/interiors/forge/CreateInteriorsForge.java +++ b/forge/src/main/java/com/sudolev/interiors/forge/CreateInteriorsForge.java @@ -13,9 +13,6 @@ public CreateInteriorsForge() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); IEventBus forgeEventBus = MinecraftForge.EVENT_BUS; - forgeEventBus.register(Events.ClientModBusEvents.class); - modEventBus.addListener(Events.ClientModBusEvents::onLoadComplete); - CreateInteriors.init(); CreateInteriors.REGISTRATE.registerEventListeners(modEventBus); } diff --git a/forge/src/main/java/com/sudolev/interiors/forge/Events.java b/forge/src/main/java/com/sudolev/interiors/forge/Events.java deleted file mode 100644 index 06fa4eb..0000000 --- a/forge/src/main/java/com/sudolev/interiors/forge/Events.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.sudolev.interiors.forge; - - -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.ConfigScreenHandler; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.ModContainer; -import net.minecraftforge.fml.ModList; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; - -import com.sudolev.interiors.CreateInteriors; - -public abstract class Events { - @Mod.EventBusSubscriber(modid = CreateInteriors.ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) - public static abstract class ClientModBusEvents { - @SubscribeEvent - static void onLoadComplete(FMLLoadCompleteEvent event) { -// ModContainer container = ModList.get() -// .getModContainerById(CreateInteriors.ID) -// .orElseThrow(() -> new IllegalStateException("Create: Interiors mod container missing on LoadComplete")); -// container.registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, -// () -> new ConfigScreenHandler.ConfigScreenFactory(CIConfigs::createConfigScreen)); - } - } -}