Skip to content

Commit

Permalink
Merge pull request #10 from rhysdh540/main
Browse files Browse the repository at this point in the history
Fix seat height bug on contraptions
  • Loading branch information
a0a7 authored Oct 24, 2023
2 parents 7bf4e38 + 0458d56 commit 7b5d8f2
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 75 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ build
.gradle
run
.DS_Store
src/main/resources/assets/create
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ minecraft_version = 1.20.1
parchment_version = 2023.06.26
# Quilt Mappings - https://lambdaurora.dev/tools/import_quilt.html
quilt_mappings = 23
# NeoForge: https://files.minecraftforge.net/net/minecraftforge/forge/index_1.19.2.html
# NeoForge: https://neoforged.net/
neo_version = 47.1.65

# Mod Dependencies
## Mod Dependencies
# Create, Registrate, and Flywheel: https://github.com/Creators-of-Create/Create/wiki/Depending-on-Create#types-of-dependencies
registrate_version = MC1.20-1.3.3
create_version = 0.5.1.e-22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

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;
Expand All @@ -18,13 +23,9 @@
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

import com.simibubi.create.AllItems;
import com.simibubi.create.foundation.utility.BlockHelper;
import com.sudolev.interiors.content.entity.BigSeatEntity;
import com.sudolev.interiors.content.registry.CIBlocks;

import org.jetbrains.annotations.NotNull;

@SuppressWarnings("NullableProblems")
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,8 +39,7 @@ public VoxelShape shape() {
return SHAPE;
}

@Override
public void doSitDown(@NotNull Level world, @NotNull BlockPos pos, @NotNull Entity entity) {
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);
Expand Down Expand Up @@ -80,7 +80,7 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player
}

if(!world.isClientSide) {
doSitDown(world, pos, getLeashed(world, player).or(player));
sitDown(world, pos, getLeashed(world, player).or(player));
}
return InteractionResult.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
package com.sudolev.interiors.content.block.seat;

import static com.sudolev.interiors.content.block.seat.ChairBlock.ArmrestConfiguration.BOTH;
import static com.sudolev.interiors.content.block.seat.ChairBlock.ArmrestConfiguration.DEFAULT;
import static com.sudolev.interiors.content.block.seat.ChairBlock.ArmrestConfiguration.LEFT;
import static com.sudolev.interiors.content.block.seat.ChairBlock.ArmrestConfiguration.NONE;
import static com.sudolev.interiors.content.block.seat.ChairBlock.ArmrestConfiguration.RIGHT;

import javax.annotation.ParametersAreNonnullByDefault;

import com.simibubi.create.foundation.block.ProperWaterloggedBlock;
import com.simibubi.create.foundation.utility.Lang;

import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -36,6 +25,13 @@
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

import com.simibubi.create.foundation.block.ProperWaterloggedBlock;
import com.simibubi.create.foundation.utility.Lang;

import javax.annotation.ParametersAreNonnullByDefault;

import static com.sudolev.interiors.content.block.seat.ChairBlock.ArmrestConfiguration.*;

@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public abstract class ChairBlock extends DirectionalSeatBlock implements ProperWaterloggedBlock {
Expand All @@ -55,7 +51,8 @@ public static VoxelShape rotateShape(Direction from, Direction to, VoxelShape sh

int times = (to.ordinal() - from.get2DDataValue() + 4) % 4;
for(int i = 0; i < times; i++) {
buffer[0].forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = Shapes.or(buffer[1], Shapes.create(1 - maxZ, minY, minX, 1 - minZ, maxY, maxX)));
buffer[0].forAllBoxes((minX, minY, minZ, maxX, maxY, maxZ) ->
buffer[1] = Shapes.or(buffer[1], Shapes.create(1 - maxZ, minY, minX, 1 - minZ, maxY, maxX)));
buffer[0] = buffer[1];
buffer[1] = Shapes.empty();
}
Expand All @@ -75,10 +72,6 @@ public BlockState getStateForPlacement(BlockPlaceContext context) {

public abstract VoxelShape shape();

public void doSitDown(Level world, BlockPos pos, Entity entity) {
sitDown(world, pos, entity);
}

@Override
public void updateEntityAfterFallOn(BlockGetter reader, Entity entity) {
BlockPos pos = entity.blockPosition();
Expand All @@ -97,30 +90,21 @@ public void updateEntityAfterFallOn(BlockGetter reader, Entity entity) {
return;
}
if(reader.getBlockState(pos).getBlock() != this) return;
doSitDown(entity.level(), pos, entity);
sitDown(entity.level(), pos, entity);
}

@Override
public InteractionResult onWrenched(BlockState state, UseOnContext context) {
Level world = context.getLevel();
BlockPos pos = context.getClickedPos();
Direction face = context.getClickedFace();

Vec3 clickPos = pos.getCenter().subtract(context.getClickLocation());

state = switch(state.getValue(FACING)) {
case NORTH ->
face == Direction.SOUTH ? toggleBackCrop(state) :
(clickPos.x > 0 ? toggleLeft(state) : toggleRight(state));
case SOUTH ->
face == Direction.NORTH ? toggleBackCrop(state) :
clickPos.x < 0 ? toggleLeft(state) : toggleRight(state);
case WEST ->
face == Direction.EAST ? toggleBackCrop(state) :
clickPos.z < 0 ? toggleLeft(state) : toggleRight(state);
case EAST ->
face == Direction.WEST ? toggleBackCrop(state) :
clickPos.z > 0 ? toggleLeft(state) : toggleRight(state);
case NORTH -> clickPos.x > 0 ? toggleLeft(state) : toggleRight(state);
case SOUTH -> clickPos.x < 0 ? toggleLeft(state) : toggleRight(state);
case WEST -> clickPos.z < 0 ? toggleLeft(state) : toggleRight(state);
case EAST -> clickPos.z > 0 ? toggleLeft(state) : toggleRight(state);
default -> state;
};

Expand Down Expand Up @@ -160,10 +144,7 @@ public InteractionResult onSneakWrenched(BlockState state, UseOnContext context)
BlockPos pos = context.getClickedPos();

if(!world.isClientSide) {
world.setBlock(pos, state.setValue(ARMRESTS, switch(state.getValue(ARMRESTS)) {
case BOTH, LEFT, RIGHT -> NONE;
case NONE -> BOTH;
}), 3);
world.setBlock(pos, toggleBackCrop(state), 3);
}

return InteractionResult.SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;

import net.minecraftforge.entity.IEntityAdditionalSpawnData;

public class BigSeatEntity extends SeatEntity implements IEntityAdditionalSpawnData {
public class BigSeatEntity extends SeatEntity {

public BigSeatEntity(EntityType<?> type, Level world) {
super(type, world);
Expand All @@ -23,13 +21,18 @@ public BigSeatEntity(Level world, BlockPos pos) {
}

@SuppressWarnings("unchecked")
public static EntityType.Builder<BigSeatEntity> build(Builder<?> builder) {
return ((EntityType.Builder<BigSeatEntity>) builder).sized(0.25f, 0.85f);
public static Builder<BigSeatEntity> build(Builder<?> builder) {
return ((Builder<BigSeatEntity>) builder).sized(0.25f, 0.85f);
}

@Override
public Vec3 getDismountLocationForPassenger(LivingEntity entity) {
return super.getDismountLocationForPassenger(entity).add(0, 0.34f, 0);
}

@Override
public Vec3 getDismountLocationForPassenger(LivingEntity pLivingEntity) {
return super.getDismountLocationForPassenger(pLivingEntity).add(0, 0.34f, 0);
public double getPassengersRidingOffset() {
return super.getPassengersRidingOffset() + 0.34;
}

public static class Render extends SeatEntity.Render {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.sudolev.interiors.foundation.mixin;

import java.util.UUID;

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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import com.simibubi.create.content.contraptions.AbstractContraptionEntity;
import com.simibubi.create.content.contraptions.Contraption;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Vec3i;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;

import com.sudolev.interiors.content.block.seat.BigChairBlock;

@Mixin(value = AbstractContraptionEntity.class, remap = false)
public abstract class AbstractContraptionEntityMixin {

@Shadow
protected Contraption contraption;

@Inject(method = "getPassengerPosition", at = @At("TAIL"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private void raise(Entity passenger, float partialTicks, CallbackInfoReturnable<Vec3> cir, UUID id, AABB bb, double ySize, BlockPos seat, Vec3 transformedVector) {
Vec3 vec3 = cir.getReturnValue();
if(contraption.getBlocks().get(seat).state().getBlock() instanceof BigChairBlock) {
cir.setReturnValue(vec3.add(0, 0.34, 0));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.sudolev.interiors.foundation.mixin;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
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.sudolev.interiors.content.block.seat.BigChairBlock;
import com.sudolev.interiors.content.entity.BigSeatEntity;

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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(value = SeatBlock.class, remap = false)
public abstract class SeatBlockMixin {

@Inject(method = "isSeatOccupied", at = @At("HEAD"), cancellable = true)
private static void sitDown(Level world, BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
if(!world.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 createSeatEntity(Level world, BlockPos pos) {
return world.getBlockState(pos).getBlock() instanceof BigChairBlock
? new BigSeatEntity(world, pos)
: new SeatEntity(world, pos);
}

@Inject(method = "sitDown", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z"), locals = LocalCapture.CAPTURE_FAILHARD)
private static void getY(Level world, BlockPos pos, Entity entity, CallbackInfo ci, SeatEntity seat) {
if(seat instanceof BigSeatEntity) {
seat.setPos(seat.getX(), seat.getY() + .34f, seat.getZ());
}
}
}
22 changes: 2 additions & 20 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
modLoader = "javafml"
loaderVersion = "[${neo_version},)"
license = "MIT"
license = "GPL-3.0"
issueTrackerURL = "https://github.com/sudolev/CreateInteriorsMod/issues"

[[mods]]
Expand Down Expand Up @@ -38,26 +38,8 @@ mandatory = true
versionRange = "[${create_version},)"
ordering = "NONE"
side = "BOTH"
[[dependencies.interiors]]
modId="jei"
mandatory=false
versionRange="[0.0.0,)"
ordering="NONE"
side="CLIENT"
[[dependencies.interiors]]
modId="configured"
mandatory=false
versionRange="[0.0.0,)"
ordering="NONE"
side="CLIENT"
[[dependencies.interiors]]
modId="catalogue"
mandatory=false
versionRange="[0.0.0,)"
ordering="NONE"
side="CLIENT"

[modproperties.interiors]
catalogueImageIcon="icon.png"
catalogueBackground="background.png"
catalogueBackground="mod_banner.png"
configuredBackground="create:textures/block/seat/top_red.png"
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"east": {"uv": [0, 5, 16, 0], "rotation": 270, "texture": "#side_top"},
"south": {"uv": [0, 16, 16, 0], "texture": "#side_top"},
"west": {"uv": [0, 5, 16, 0], "rotation": 90, "texture": "#side_top"},
"up": {"uv": [0, 8, 16, 13], "texture": "#top"},
"up": {"uv": [0, 8, 16, 13], "texture": "#side_top"},
"down": {"uv": [0, 0, 16, 8], "texture": "#missing"}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"east": {"uv": [0, 5, 16, 0], "rotation": 270, "texture": "#side_top"},
"south": {"uv": [0, 16, 16, 0], "texture": "#side_top"},
"west": {"uv": [0, 5, 16, 0], "rotation": 90, "texture": "#side_top"},
"up": {"uv": [0, 8, 16, 13], "texture": "#top"},
"up": {"uv": [0, 8, 16, 13], "texture": "#side_top"},
"down": {"uv": [0, 0, 16, 8], "texture": "#missing"}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"east": {"uv": [0, 5, 16, 0], "rotation": 270, "texture": "#side_top"},
"south": {"uv": [0, 16, 16, 0], "texture": "#side_top"},
"west": {"uv": [0, 5, 16, 0], "rotation": 90, "texture": "#side_top"},
"up": {"uv": [0, 8, 16, 13], "texture": "#top"},
"up": {"uv": [0, 8, 16, 13], "texture": "#side_top"},
"down": {"uv": [0, 0, 16, 8], "texture": "#missing"}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"east": {"uv": [0, 5, 16, 0], "rotation": 270, "texture": "#side_top"},
"south": {"uv": [0, 16, 16, 0], "texture": "#side_top"},
"west": {"uv": [0, 5, 16, 0], "rotation": 90, "texture": "#side_top"},
"up": {"uv": [0, 8, 16, 13], "texture": "#top"},
"up": {"uv": [0, 8, 16, 13], "texture": "#side_top"},
"down": {"uv": [0, 0, 16, 8], "texture": "#missing"}
}
},
Expand Down
Binary file removed src/main/resources/background.png
Binary file not shown.
3 changes: 2 additions & 1 deletion src/main/resources/interiors.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"compatibilityLevel": "JAVA_17",
"client": [],
"mixins": [

"AbstractContraptionEntityMixin",
"SeatBlockMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
Binary file modified src/main/resources/mod_banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/wordmark.png
Binary file not shown.

0 comments on commit 7b5d8f2

Please sign in to comment.