Overhauled Bogey Style

This commit is contained in:
Rabbitminers 2023-04-30 20:01:00 +01:00
parent 53240bd42f
commit e10d07ddc3

View file

@ -3,8 +3,8 @@ package com.simibubi.create.content.logistics.trains.entity;
import com.jozufozu.flywheel.api.MaterialManager;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.content.logistics.trains.BogeyRenderer;
import com.simibubi.create.content.logistics.trains.AbstractBogeyBlock;
import com.simibubi.create.content.logistics.trains.BogeyRenderer.CommonRenderer;
import com.simibubi.create.content.logistics.trains.BogeySizes;
import net.minecraft.nbt.CompoundTag;
@ -13,47 +13,48 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ForgeRegistryEntry;
import net.minecraftforge.registries.IForgeRegistryEntry;
import org.jetbrains.annotations.NotNull;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
public final class BogeyStyle extends ForgeRegistryEntry<BogeyStyle> implements IForgeRegistryEntry<BogeyStyle> {
public Map<BogeySizes.BogeySize, ResourceLocation> blocks = new HashMap<>();
public Component displayName;
public ResourceLocation soundType;
public CompoundTag defaultData;
public BogeyRenderer renderer;
public class BogeyStyle {
public final ResourceLocation name;
private final Optional<CommonRenderer> commonRenderer;
private final Map<BogeySizes.BogeySize, SizeData> sizes;
public final Component displayName;
public final ResourceLocation soundType;
public final CompoundTag defaultData;
public <T extends AbstractBogeyBlock> void addBlockForSize(BogeySizes.BogeySize size, T block) {
this.addBlockForSize(size, block.getRegistryName());
}
public BogeyStyle(ResourceLocation name, Component displayName, ResourceLocation soundType, CompoundTag defaultData,
Map<BogeySizes.BogeySize, SizeData> sizes, Optional<CommonRenderer> commonRenderer) {
this.name = name;
this.displayName = displayName;
this.soundType = soundType;
this.defaultData = defaultData;
public void addBlockForSize(BogeySizes.BogeySize size, ResourceLocation location) {
blocks.put(size, location);
this.sizes = sizes;
this.commonRenderer = commonRenderer;
}
public Block getNextBlock(BogeySizes.BogeySize currentSize) {
return Stream.iterate(currentSize.increment(), BogeySizes.BogeySize::increment)
.filter(size -> blocks.containsKey(size))
.filter(sizes::containsKey)
.findFirst()
.map(size -> ForgeRegistries.BLOCKS.getValue(blocks.get(size)))
.orElse(ForgeRegistries.BLOCKS.getValue(blocks.get(currentSize)));
.map(size -> ForgeRegistries.BLOCKS.getValue(sizes.get(size).block()))
.orElse(ForgeRegistries.BLOCKS.getValue(sizes.get(currentSize).block()));
}
public Block getBlockOfSize(BogeySizes.BogeySize size) {
return ForgeRegistries.BLOCKS.getValue(blocks.get(size));
return ForgeRegistries.BLOCKS.getValue(sizes.get(size).block());
}
public Set<BogeySizes.BogeySize> validSizes() {
return blocks.keySet();
return sizes.keySet();
}
@NotNull
@ -63,7 +64,26 @@ public final class BogeyStyle extends ForgeRegistryEntry<BogeyStyle> implements
return entry.getMainEvent();
}
public BogeyRenderer createRendererInstance(BogeySizes.BogeySize size) {
return this.getInWorldRenderInstance(size).createNewInstance();
}
public BogeyRenderer getInWorldRenderInstance(BogeySizes.BogeySize size) {
return this.sizes.get(size).renderer();
}
public Optional<CommonRenderer> getInWorldCommonRenderInstance() {
return this.commonRenderer;
}
public Optional<CommonRenderer> getNewCommonRenderInstance() {
return this.getInWorldCommonRenderInstance().map(CommonRenderer::createNewInstance);
}
public BogeyInstance createInstance(CarriageBogey bogey, BogeySizes.BogeySize size, MaterialManager materialManager) {
return new BogeyInstance(bogey, this.renderer.newInstance(), size, materialManager);
return new BogeyInstance(bogey, this, size, materialManager);
}
public record SizeData(ResourceLocation block, BogeyRenderer renderer) {
}
}