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