Added Size Transforms If Size Is Not Available For New Style
This commit is contained in:
parent
96566b1614
commit
1ad5ae9514
5 changed files with 58 additions and 17 deletions
|
@ -6,6 +6,7 @@ import java.util.Comparator;
|
|||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -18,6 +19,7 @@ import com.simibubi.create.AllItems;
|
|||
import com.simibubi.create.AllRegistries;
|
||||
import com.simibubi.create.content.contraptions.wrench.IWrenchable;
|
||||
import com.simibubi.create.content.logistics.trains.entity.BogeyStyle;
|
||||
import com.simibubi.create.content.logistics.trains.track.StandardBogeyBlock;
|
||||
import com.simibubi.create.content.logistics.trains.track.StandardBogeyTileEntity;
|
||||
import com.simibubi.create.content.schematics.ISpecialBlockItemRequirement;
|
||||
import com.simibubi.create.content.schematics.ItemRequirement;
|
||||
|
@ -31,13 +33,12 @@ import net.minecraft.client.renderer.MultiBufferSource;
|
|||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
|
@ -143,7 +144,8 @@ public abstract class AbstractBogeyBlock extends Block implements ITE<StandardBo
|
|||
return InteractionResult.CONSUME;
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
|
||||
if (!player.isShiftKeyDown() && stack.is(AllItems.WRENCH.get()) && !player.getCooldowns().isOnCooldown(stack.getItem())) {
|
||||
if (!player.isShiftKeyDown() && stack.is(AllItems.WRENCH.get()) && !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
&& AllRegistries.BOGEY_REGISTRY.get().getValues().size() > 1) {
|
||||
Collection<BogeyStyle> styles = AllRegistries.BOGEY_REGISTRY.get().getValues();
|
||||
|
||||
if (styles.size() <= 1)
|
||||
|
@ -156,25 +158,36 @@ public abstract class AbstractBogeyBlock extends Block implements ITE<StandardBo
|
|||
|
||||
player.getCooldowns().addCooldown(stack.getItem(), 20);
|
||||
BogeyStyle currentStyle = sbte.getStyle();
|
||||
BogeyRenderer.BogeySize size = getSize();
|
||||
|
||||
Optional<BogeyStyle> style = styles.stream()
|
||||
.map(s -> getNextStyle(currentStyle))
|
||||
.filter(s -> s.validSizes().contains(getSize()))
|
||||
.findFirst();
|
||||
BogeyStyle style = this.getNextStyle(currentStyle);
|
||||
Set<BogeyRenderer.BogeySize> validSizes = style.validSizes();
|
||||
|
||||
if (style.isPresent()) {
|
||||
player.displayClientMessage(Lang.translateDirect("create.bogey.style.updated_style"), true);
|
||||
sbte.setBogeyStyle(style.get());
|
||||
return InteractionResult.CONSUME;
|
||||
} else {
|
||||
player.displayClientMessage(Lang.translateDirect("create.bogey.style.no_other_sizes"), true);
|
||||
return InteractionResult.FAIL;
|
||||
for (int i = 0; i < BogeyRenderer.BogeySize.values().length; i++) {
|
||||
if (validSizes.contains(size)) break;
|
||||
size = size.increment();
|
||||
}
|
||||
|
||||
sbte.setBogeyStyle(style);
|
||||
|
||||
if (size == getSize()) {
|
||||
player.displayClientMessage(Lang.translateDirect("create.bogey.style.updated_style"), true);
|
||||
} else {
|
||||
CompoundTag oldData = sbte.getBogeyData();
|
||||
level.setBlock(pos, this.getStateOfSize(sbte, size), 3);
|
||||
BlockEntity newBlockEntity = level.getBlockEntity(pos);
|
||||
if (!(newBlockEntity instanceof StandardBogeyTileEntity newTileEntity))
|
||||
return InteractionResult.FAIL;
|
||||
newTileEntity.setBogeyData(oldData);
|
||||
player.displayClientMessage(Lang.translateDirect("create.bogey.style.updated_style_and_size"), true);
|
||||
}
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState getRotatedBlockState(BlockState state, Direction targetedFace) {
|
||||
Block block = state.getBlock();
|
||||
|
@ -217,6 +230,14 @@ public abstract class AbstractBogeyBlock extends Block implements ITE<StandardBo
|
|||
: nextBlock;
|
||||
}
|
||||
|
||||
public BlockState getStateOfSize(StandardBogeyTileEntity sbte, BogeyRenderer.BogeySize size) {
|
||||
BogeyStyle style = sbte.getStyle();
|
||||
BlockState state = style.getBlockOfSize(size).defaultBlockState();
|
||||
return state.hasProperty(WATERLOGGED)
|
||||
? state.setValue(WATERLOGGED, sbte.getBlockState().getValue(WATERLOGGED))
|
||||
: state;
|
||||
}
|
||||
|
||||
public BogeyStyle getNextStyle(Level level, BlockPos pos) {
|
||||
BlockEntity te = level.getBlockEntity(pos);
|
||||
if (te instanceof StandardBogeyTileEntity sbte)
|
||||
|
@ -233,6 +254,7 @@ public abstract class AbstractBogeyBlock extends Block implements ITE<StandardBo
|
|||
return Iterate.cycleValue(list, style);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public @NotNull BlockState rotate(@NotNull BlockState pState, Rotation pRotation) {
|
||||
return switch (pRotation) {
|
||||
|
|
|
@ -173,5 +173,9 @@ public abstract class BogeyRenderer {
|
|||
// TODO: REPLACE THIS SO THAT IT CAN BE ADDED TO
|
||||
public enum BogeySize {
|
||||
SMALL, LARGE;
|
||||
|
||||
public BogeySize increment() {
|
||||
return values()[(ordinal() + 1) % values().length];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,10 @@ public final class BogeyStyle extends ForgeRegistryEntry<BogeyStyle> implements
|
|||
.orElse(ForgeRegistries.BLOCKS.getValue(blocks.get(currentSize)));
|
||||
}
|
||||
|
||||
public Block getBlockOfSize(BogeySize size) {
|
||||
return ForgeRegistries.BLOCKS.getValue(blocks.get(size));
|
||||
}
|
||||
|
||||
public Set<BogeySize> validSizes() {
|
||||
return blocks.keySet();
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ import com.simibubi.create.foundation.utility.WorldAttached;
|
|||
import com.simibubi.create.foundation.utility.animation.LerpedFloat;
|
||||
import com.simibubi.create.foundation.utility.animation.LerpedFloat.Chaser;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
|
@ -276,7 +277,19 @@ public class StationTileEntity extends SmartTileEntity implements ITransformable
|
|||
.offset(up);
|
||||
BlockState blockState = level.getBlockState(bogeyPos);
|
||||
if (blockState.getBlock() instanceof AbstractBogeyBlock bogey) {
|
||||
level.setBlock(bogeyPos, bogey.getRotatedBlockState(blockState, Direction.DOWN), 3);
|
||||
BlockEntity be = level.getBlockEntity(bogeyPos);
|
||||
if (!(be instanceof StandardBogeyTileEntity oldTE))
|
||||
continue;
|
||||
CompoundTag oldData = oldTE.getBogeyData();
|
||||
BlockState newBlock = bogey.getNextSize(oldTE);
|
||||
if (newBlock.getBlock() == bogey)
|
||||
player.displayClientMessage(Lang.translateDirect("create.bogey.style.no_other_sizes")
|
||||
.withStyle(ChatFormatting.RED), true);
|
||||
level.setBlock(bogeyPos, newBlock, 3);
|
||||
BlockEntity newEntity = level.getBlockEntity(bogeyPos);
|
||||
if (!(newEntity instanceof StandardBogeyTileEntity newTE))
|
||||
continue;
|
||||
newTE.setBogeyData(oldData);
|
||||
bogey.playRotateSound(level, bogeyPos);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -48,8 +48,6 @@ public class BogeyStyleBuilder<T extends BogeyStyle, P> extends AbstractBuilder<
|
|||
this.style = style;
|
||||
this.particles = AllParticleTypes.AIR_FLOW::get;
|
||||
this.data = CompoundTag::new;
|
||||
this.block(BogeyRenderer.BogeySize.SMALL, AllBlocks.SMALL_BOGEY);
|
||||
this.block(BogeyRenderer.BogeySize.LARGE, AllBlocks.LARGE_BOGEY);
|
||||
}
|
||||
|
||||
public BogeyStyleBuilder<T, P> defaultData(CompoundTag data) {
|
||||
|
|
Loading…
Reference in a new issue