Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 26.1.2 -999999999-01-01T00:00:00 Language (en_us)
5589189dc52ef213076f236794a99c7c38f6fdd6 assets/xkdeco/lang/en_us.json
b56fa71f361d6b7935df5d77d39ef84227f9e38c assets/xkdeco/lang/en_us.json
1 change: 1 addition & 0 deletions src/generated/resources/assets/xkdeco/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"item.xkdeco.mimic_wall": "Mimic %s",
"modmenu.descriptionTranslation.xkdeco": "Models and textures are created by XeKr: https://github.com/XeKr",
"modmenu.nameTranslation.xkdeco": "XeKr's Decoration",
"tip.xkdeco.block_unlocked": "%s has been unlocked.",
"xkdeco.config.mimicWalls": "Mimic Walls",
"xkdeco.config.mimicWalls.desc": "",
"xkdeco.mimic_walls": "Mimic Walls"
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/teacon/xkdeco/block/AirDuctBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

public class AirDuctBlock extends BasicBlock {

private static final Direction[] DIRECTIONS = Direction.values();

public AirDuctBlock(Properties pProperties) {
super(pProperties);
BlockState blockState = this.stateDefinition.any();
Expand Down Expand Up @@ -94,7 +92,7 @@ public BlockState getStateForPlacement(BlockPlaceContext pContext) {
BlockPos pos = pContext.getClickedPos();
BlockPos.MutableBlockPos mutable = pos.mutable();
List<Direction> neighbors = Lists.newArrayList();
for (Direction direction : DIRECTIONS) {
for (Direction direction : Block.UPDATE_SHAPE_ORDER) {
BlockState neighborState = level.getBlockState(mutable.setWithOffset(pos, direction));
if (isAirDuctSlot(neighborState, direction.getOpposite())) {
neighbors.add(direction);
Expand Down Expand Up @@ -128,7 +126,7 @@ protected BlockState updateShape(
}
BlockPos.MutableBlockPos mutable = pos.mutable();
List<Direction> neighbors = Lists.newArrayListWithExpectedSize(2);
for (Direction direction : DIRECTIONS) {
for (Direction direction : Block.UPDATE_SHAPE_ORDER) {
if (direction == pDirection) {
continue;
}
Expand All @@ -141,7 +139,7 @@ protected BlockState updateShape(
}
}
Direction theOtherDirection = neighbors.isEmpty() ? pDirection.getOpposite() : neighbors.getFirst();
for (Direction direction : DIRECTIONS) {
for (Direction direction : Block.UPDATE_SHAPE_ORDER) {
blockState = blockState.setValue(
DIRECTION_PROPERTIES.get(direction.get3DDataValue()),
direction == pDirection || direction == theOtherDirection);
Expand Down
50 changes: 42 additions & 8 deletions src/main/java/org/teacon/xkdeco/block/DisplayBlock.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.teacon.xkdeco.block;

import org.teacon.xkdeco.blockentity.SingleSlotContainerBlockEntity;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.Container;
Expand All @@ -12,11 +16,17 @@
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ItemContainerContents;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.ticks.ContainerSingleItem;
import snownee.kiwi.block.ModBlock;
import snownee.kiwi.customization.block.CheckedWaterloggedBlock;

Expand All @@ -34,13 +44,30 @@ protected InteractionResult useItemOn(
Player player,
InteractionHand hand,
BlockHitResult hitResult) {
if (checkLock(player, level, pos)) {
return InteractionResult.SUCCESS;
}
if (doesHitTop(hitResult)) {
return useTop(stack, state, level, pos, player, hand, hitResult);
} else {
return useSide(stack, state, level, pos, player, hand, hitResult);
}
}

private boolean checkLock(Player player, Level level, BlockPos pos) {
if (!level.isClientSide() && level.getBlockEntity(pos) instanceof SingleSlotContainerBlockEntity container &&
container.isLocked()) {
if (container.canOpen(player)) {
container.unlock();
player.sendOverlayMessage(Component.translatable("tip.xkdeco.block_unlocked", getName()));
} else {
BaseContainerBlockEntity.sendChestLockedNotifications(Vec3.atCenterOf(pos), player, getName());
}
return true;
}
return false;
}

protected InteractionResult useSide(
ItemStack held,
BlockState pState,
Expand All @@ -60,7 +87,7 @@ protected InteractionResult useTop(
Player pPlayer,
InteractionHand pHand,
BlockHitResult pHit) {
if (!(pLevel.getBlockEntity(pPos) instanceof Container container)) {
if (!(pLevel.getBlockEntity(pPos) instanceof ContainerSingleItem container)) {
return InteractionResult.FAIL;
}
if (pLevel.isClientSide()) {
Expand All @@ -75,6 +102,9 @@ protected InteractionResult useTop(
}

public void click(BlockState blockState, Level level, BlockPos pos, ServerPlayer player, BlockHitResult hit) {
if (checkLock(player, level, pos)) {
return;
}
if (doesHitTop(hit)) {
clickTop(blockState, level, pos, player, hit);
} else {
Expand All @@ -88,18 +118,18 @@ protected void clickTop(BlockState blockState, Level level, BlockPos pos, Server
grab(blockState, level, pos, player);
}

public boolean insertItem(Container container, ItemStack itemStack) {
public boolean insertItem(ContainerSingleItem container, ItemStack itemStack) {
if (!container.canPlaceItem(0, itemStack)) {
return false;
}
ItemStack displayed = container.getItem(0);
ItemStack displayed = container.getTheItem();
if (displayed.isEmpty() || ItemStack.isSameItemSameComponents(displayed, itemStack)) {
int maxSize = Math.min(itemStack.getMaxStackSize(), container.getMaxStackSize());
int transferAmount = Math.min(itemStack.getCount(), maxSize - displayed.getCount());
if (transferAmount > 0) {
ItemStack split = itemStack.split(transferAmount);
split.grow(displayed.getCount());
container.setItem(0, split);
container.setTheItem(split);
return true;
}
}
Expand All @@ -110,22 +140,21 @@ public boolean insertItem(Container container, ItemStack itemStack) {
public void stepOn(Level pLevel, BlockPos pPos, BlockState pState, Entity pEntity) {
super.stepOn(pLevel, pPos, pState, pEntity);
if (!pLevel.isClientSide() && pEntity instanceof ItemEntity itemEntity &&
pLevel.getBlockEntity(pPos) instanceof Container container) {
pLevel.getBlockEntity(pPos) instanceof ContainerSingleItem container) {
if (insertItem(container, itemEntity.getItem())) {
itemEntity.setItem(itemEntity.getItem()); // send update packet
}
}
}

public void grab(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer) {
if (pLevel.isClientSide() || !(pLevel.getBlockEntity(pPos) instanceof Container be)) {
if (pLevel.isClientSide() || !(pLevel.getBlockEntity(pPos) instanceof ContainerSingleItem be)) {
return;
}
ItemStack item = be.getItem(0);
ItemStack item = be.removeTheItem();
if (item.isEmpty()) {
return;
}
be.setItem(0, ItemStack.EMPTY);
double d3 = pPos.getX() + 0.5;
double d4 = pPos.getY() + 1;
double d5 = pPos.getZ() + 0.5;
Expand Down Expand Up @@ -161,4 +190,9 @@ public int getAnalogOutputSignal(BlockState pBlockState, Level pLevel, BlockPos
public boolean canBeDestroyed(BlockState blockState, Level level, BlockPos pos, Player player, BlockHitResult hit) {
return !(level.getBlockEntity(pos) instanceof Container container) || container.isEmpty();
}
Comment on lines 190 to 192

@Override
public BlockItem createItem(Item.Properties builder) {
return super.createItem(builder.component(DataComponents.CONTAINER, ItemContainerContents.EMPTY));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected void neighborChanged(
@Nullable Orientation pOrientation,
boolean pIsMoving) {
if (!pLevel.isClientSide() && pState.getValue(POWERED) != pLevel.hasNeighborSignal(pPos)) {
pLevel.setBlock(pPos, pState.cycle(POWERED), 2);
pLevel.setBlock(pPos, pState.cycle(POWERED), Block.UPDATE_CLIENTS);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public BlockDisplayBlockEntity(BlockPos pWorldPosition, BlockState pBlockState)
super(XKDecoEntityTypes.BLOCK_DISPLAY.get(), pWorldPosition, pBlockState);
}

// getRenderBoundingBox moved to BlockDisplayRenderer. See there for more info.

@Override
public int getMaxStackSize() {
return 1;
Expand All @@ -43,13 +41,13 @@ public boolean canPlaceItem(int pIndex, ItemStack pStack) {
}

@Override
public void setItem(int pSlot, ItemStack pStack) {
if (pStack.getItem() instanceof BlockItem blockItem) {
public void setTheItem(ItemStack itemStack) {
super.setTheItem(itemStack);
if (itemStack.getItem() instanceof BlockItem blockItem) {
setStoredBlockState(blockItem.getBlock().defaultBlockState());
} else {
setStoredBlockState(EMPTY);
}
super.setItem(pSlot, pStack);
}

public BlockState getStoredBlockState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,12 @@ public ItemDisplayBlockEntity(BlockPos blockPos, BlockState blockState, boolean
blockState);
}

// getRenderBoundingBox moved to ItemDisplayRenderer. See there for more info.

public boolean isProjector() {
return XKDecoEntityTypes.ITEM_PROJECTOR.get() == this.getType();
return is(XKDecoEntityTypes.ITEM_PROJECTOR.get());
}

public float getSpin() {
if (hasFixedSpin()) {
return fixedSpin;
}
return level == null ? 0 : level.getGameTime();
return fixedSpin;
}

public boolean hasFixedSpin() {
Expand Down
Loading