Skip to content

Commit

Permalink
fix bug with clicking chairs with dye
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysdh540 committed Sep 2, 2024
1 parent cedaf1d commit 57f479e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 108 deletions.
4 changes: 2 additions & 2 deletions common/src/main/java/com/sudolev/interiors/Utils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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));

Expand All @@ -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<BigSeatEntity> seats = world.getEntitiesOfClass(BigSeatEntity.class, new AABB(pos));
if(!seats.isEmpty()) {
BigSeatEntity entity = seats.get(0);
List<Entity> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,46 @@

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;

@Mixin(SeatBlock.class)
public abstract class SeatBlockMixin {

@Inject(method = "isSeatOccupied", at = @At("HEAD"), cancellable = true)
private static void weCountAsSeatsToo(Level world, BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
if(!world.getEntitiesOfClass(BigSeatEntity.class, new AABB(pos)).isEmpty())
private static void weCountAsSeatsToo(Level level, BlockPos pos, CallbackInfoReturnable<Boolean> 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))
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.fabricmc.api.ModInitializer;
import com.sudolev.interiors.CreateInteriors;


public class CreateInteriorsFabric implements ModInitializer {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
26 changes: 0 additions & 26 deletions forge/src/main/java/com/sudolev/interiors/forge/Events.java

This file was deleted.

0 comments on commit 57f479e

Please sign in to comment.