Re-worked BogeyStyles

This commit is contained in:
Rabbitminers 2023-03-30 18:47:13 +01:00
parent da593fccb1
commit d1e1f7ec5a
8 changed files with 98 additions and 37 deletions

View file

@ -1,15 +1,10 @@
package com.simibubi.create;
import com.simibubi.create.content.logistics.trains.BogeyRenderer;
import com.simibubi.create.content.logistics.trains.entity.BogeyStyle;
import com.simibubi.create.content.logistics.trains.entity.StandardBogeyInstance;
import com.tterrag.registrate.util.entry.RegistryEntry;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import static com.simibubi.create.Create.LOGGER;
import static com.simibubi.create.Create.REGISTRATE;
@ -17,7 +12,7 @@ import static com.simibubi.create.Create.REGISTRATE;
@SuppressWarnings("unused")
public class AllBogeyStyles {
public static final RegistryEntry<BogeyStyle> STANDARD = REGISTRATE
.bogeyStyle("standard", new BogeyStyle(StandardBogeyInstance.class))
.bogeyStyle("standard", new BogeyStyle())
.block(BogeyRenderer.BogeySize.SMALL, AllBlocks.SMALL_BOGEY)
.block(BogeyRenderer.BogeySize.LARGE, AllBlocks.LARGE_BOGEY)
.register();

View file

@ -30,7 +30,7 @@ import com.simibubi.create.content.contraptions.fluids.tank.FluidTankBlock;
import com.simibubi.create.content.curiosities.deco.SlidingDoorBlock;
import com.simibubi.create.content.logistics.block.redstone.RedstoneLinkBlock;
import com.simibubi.create.content.logistics.block.vault.ItemVaultBlock;
import com.simibubi.create.content.logistics.trains.IBogeyBlock;
import com.simibubi.create.content.logistics.trains.AbstractBogeyBlock;
import com.simibubi.create.content.logistics.trains.ITrackBlock;
import com.simibubi.create.content.logistics.trains.management.edgePoint.station.StationBlock;
import com.simibubi.create.foundation.config.ContraptionMovementSetting;
@ -337,7 +337,7 @@ public class BlockMovementChecks {
return direction == state.getValue(StickerBlock.FACING)
&& !isNotSupportive(world.getBlockState(pos.relative(direction)), direction.getOpposite());
}
if (block instanceof IBogeyBlock bogey)
if (block instanceof AbstractBogeyBlock bogey)
return bogey.getStickySurfaces(world, pos, state)
.contains(direction);
if (block instanceof WhistleBlock)

View file

@ -20,8 +20,8 @@ public class BogeyTileEntityRenderer<T extends BlockEntity> extends SafeTileEnti
float angle = 0;
if (te instanceof StandardBogeyTileEntity sbte)
angle = sbte.getVirtualAngle(partialTicks);
if (blockState.getBlock()instanceof IBogeyBlock bogey)
bogey.render(blockState, angle, ms, partialTicks, buffer, light, overlay);
if (blockState.getBlock()instanceof AbstractBogeyBlock bogey)
bogey.render(blockState, angle, ms, partialTicks, buffer, light, overlay, te.getTileData());
}
}

View file

@ -30,7 +30,8 @@ public abstract class BogeyInstance {
public final BogeyRenderer renderer;
private final BogeyRenderer.BogeySize size;
public BogeyInstance(CarriageBogey bogey, BogeyRenderer renderer, BogeyRenderer.BogeySize size, MaterialManager materialManager) {
public BogeyInstance(CarriageBogey bogey, BogeyRenderer renderer, BogeyRenderer.BogeySize size,
MaterialManager materialManager) {
this.bogey = bogey;
this.renderer = renderer;
this.size = size;
@ -38,6 +39,8 @@ public abstract class BogeyInstance {
renderer.initialiseContraptionModelData(materialManager, size);
}
public abstract BogeyInstanceFactory getInstanceFactory();
protected void hiddenFrame() {
beginFrame(0, null);
}
@ -61,4 +64,10 @@ public abstract class BogeyInstance {
return bogey.getAnchorPosition() != null ? bogey.getAnchorPosition()
: entity.getLightProbePosition(AnimationTickHolder.getPartialTicks());
}
@FunctionalInterface
interface BogeyInstanceFactory {
BogeyInstance create(CarriageBogey bogey, BogeyRenderer.BogeySize size,
MaterialManager materialManager);
}
}

View file

@ -1,23 +1,60 @@
package com.simibubi.create.content.logistics.trains.entity;
import com.jozufozu.flywheel.api.MaterialManager;
import com.simibubi.create.content.logistics.trains.BogeyRenderer;
import com.simibubi.create.content.logistics.trains.BogeyRenderer.BogeySize;
import com.simibubi.create.content.logistics.trains.IBogeyBlock;
import com.simibubi.create.content.logistics.trains.AbstractBogeyBlock;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ForgeRegistryEntry;
import net.minecraftforge.registries.IForgeRegistryEntry;
import java.util.EnumMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
public class BogeyStyle extends ForgeRegistryEntry<BogeyStyle> implements IForgeRegistryEntry<BogeyStyle> {
public Map<BogeySize, IBogeyBlock> blocks;
final Class<? extends BogeyInstance> instance;
public final class BogeyStyle extends ForgeRegistryEntry<BogeyStyle> implements IForgeRegistryEntry<BogeyStyle> {
public Map<BogeySize, ResourceLocation> blocks = new EnumMap<>(BogeySize.class);
public BogeyInstance.BogeyInstanceFactory instance;
public Component displayName;
public SoundType soundType;
public CompoundTag defaultData;
public BogeyRenderer renderer;
public BogeyStyle(Class<? extends BogeyInstance> instance) {
this.instance = instance;
public <T extends AbstractBogeyBlock> void addBlockForSize(BogeySize size, T block) {
this.addBlockForSize(size, block.getRegistryName());
}
public <C extends BogeyInstance> BogeyInstance getInstance() throws IllegalAccessException, InstantiationException {
return instance.newInstance();
public void addBlockForSize(BogeySize size, ResourceLocation location) {
blocks.put(size, location);
}
public Block getNextBlock(BogeySize currentSize) {
return Stream.iterate(getNextSize(currentSize), this::getNextSize)
.filter(size -> blocks.containsKey(size))
.findFirst()
.map(size -> ForgeRegistries.BLOCKS.getValue(blocks.get(size)))
.orElse(ForgeRegistries.BLOCKS.getValue(blocks.get(currentSize)));
}
public Set<BogeySize> validSizes() {
return blocks.keySet();
}
private BogeySize getNextSize(BogeySize size) {
BogeySize[] sizes = BogeySize.values();
int nextOrdinal = (size.ordinal() + 1) % sizes.length;
return sizes[nextOrdinal];
}
public BogeyInstance createInstance(CarriageBogey bogey, BogeySize size, MaterialManager materialManager) {
return instance.create(bogey, size, materialManager);
}
}

View file

@ -13,6 +13,7 @@ import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.Vec3;
public class CarriageContraptionEntityRenderer extends ContraptionEntityRenderer<CarriageContraptionEntity> {
@ -37,7 +38,7 @@ public class CarriageContraptionEntityRenderer extends ContraptionEntityRenderer
MultiBufferSource buffers, int overlay) {
if (!entity.validForRender || entity.firstPositionUpdate)
return;
super.render(entity, yaw, partialTicks, ms, buffers, overlay);
Carriage carriage = entity.getCarriage();
@ -65,8 +66,10 @@ public class CarriageContraptionEntityRenderer extends ContraptionEntityRenderer
translateBogey(ms, bogey, bogeySpacing, viewYRot, viewXRot, partialTicks);
int light = getBogeyLightCoords(entity, bogey, partialTicks);
BlockEntity be = entity.getContraption().presentTileEntities.get(bogeyPos);
bogey.type.render(null, bogey.wheelAngle.getValue(partialTicks), ms, partialTicks, buffers, light,
overlay);
overlay, be.getTileData());
ms.popPose();
}

View file

@ -17,4 +17,9 @@ public class StandardBogeyInstance extends BogeyInstance {
public static StandardBogeyInstance frame(CarriageBogey bogey, MaterialManager materialManager) {
return new StandardBogeyInstance(bogey, BogeyRenderer.BogeySize.SMALL, materialManager);
}
@Override
public BogeyInstanceFactory getInstanceFactory() {
return StandardBogeyInstance::new;
}
}

View file

@ -1,10 +1,10 @@
package com.simibubi.create.foundation.data;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllParticleTypes;
import com.simibubi.create.AllRegistries;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.content.logistics.trains.BogeyRenderer;
import com.simibubi.create.content.logistics.trains.IBogeyBlock;
import com.simibubi.create.content.logistics.trains.AbstractBogeyBlock;
import com.simibubi.create.content.logistics.trains.entity.BogeyStyle;
import com.tterrag.registrate.AbstractRegistrate;
@ -14,28 +14,27 @@ import com.tterrag.registrate.builders.AbstractBuilder;
import com.tterrag.registrate.builders.BuilderCallback;
import com.tterrag.registrate.util.entry.BlockEntry;
import com.tterrag.registrate.util.entry.RegistryEntry;
import com.tterrag.registrate.util.nullness.NonNullSupplier;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.SoundType;
import org.jetbrains.annotations.NotNull;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.EnumMap;
import java.util.Map;
import java.util.function.Supplier;
@ParametersAreNonnullByDefault
public class BogeyStyleBuilder<T extends BogeyStyle, P> extends AbstractBuilder<BogeyStyle, T, P, BogeyStyleBuilder<T, P>> {
private final T style;
private NonNullSupplier<Map<BogeyRenderer.BogeySize, BlockEntry<? extends IBogeyBlock>>> bogeyBlocks
= () -> new EnumMap<>(BogeyRenderer.BogeySize.class);
private Supplier<AllSoundEvents.SoundEntry> sounds;
private NonNullSupplier<BogeyRenderer> renderer;
private Supplier<SoundType> soundType;
private Supplier<CompoundTag> data;
private Supplier<ParticleType<?>> particles;
@ -46,9 +45,10 @@ public class BogeyStyleBuilder<T extends BogeyStyle, P> extends AbstractBuilder<
protected BogeyStyleBuilder(AbstractRegistrate<?> owner, P parent, String name, BuilderCallback callback, T style) {
super(owner, parent, name, callback, AllRegistries.Keys.BOGEYS);
this.style = style;
// bogeyBlocks.get().put(BogeyRenderer.BogeySize.SMALL, AllBlocks.SMALL_BOGEY.get());
// bogeyBlocks.get().put(BogeyRenderer.BogeySize.LARGE, AllBlocks.LARGE_BOGEY.get());
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) {
@ -61,18 +61,30 @@ public class BogeyStyleBuilder<T extends BogeyStyle, P> extends AbstractBuilder<
return this;
}
public BogeyStyleBuilder<T, P> soundType(AllSoundEvents.SoundEntry soundEntry) {
this.sounds = () -> soundEntry;
public BogeyStyleBuilder<T, P> soundType(SoundType soundEntry) {
this.soundType = () -> soundEntry;
return this;
}
public BogeyStyleBuilder<T, P> block(BogeyRenderer.BogeySize size, BlockEntry<? extends IBogeyBlock> block) {
this.bogeyBlocks.get().put(size, block);
public BogeyStyleBuilder<T, P> block(BogeyRenderer.BogeySize size, BlockEntry<? extends AbstractBogeyBlock> block) {
return this.block(size, block.getId());
}
public BogeyStyleBuilder<T, P> block(BogeyRenderer.BogeySize size, ResourceLocation location) {
this.style.addBlockForSize(size, location);
return this;
}
public BogeyStyleBuilder<T, P> renderer(BogeyRenderer renderer) {
this.renderer = () -> renderer;
return this;
}
@Override
protected @NotNull T createEntry() {
style.soundType = soundType.get();
style.defaultData = data.get();
style.renderer = renderer.get();
return style;
}
}