mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-14 14:13:49 +01:00
Filtering for filters
- Allow filtering for filters when filter is empty - Refine waterwheel model generation code
This commit is contained in:
parent
7e67a4a74a
commit
aa102dfabd
4 changed files with 67 additions and 34 deletions
|
@ -42,7 +42,6 @@ public class WaterWheelInstance<T extends WaterWheelBlockEntity> extends CutoutR
|
|||
return getRotatingMaterial().model(key, () -> {
|
||||
BakedModel model = WaterWheelRenderer.generateModel(key);
|
||||
BlockState state = key.state();
|
||||
// TODO waterwheels
|
||||
Direction dir;
|
||||
if (key.large()) {
|
||||
dir = Direction.fromAxisAndDirection(state.getValue(LargeWaterWheelBlock.AXIS), AxisDirection.POSITIVE);
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.util.Map;
|
|||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
import com.jozufozu.flywheel.core.PartialModel;
|
||||
import com.jozufozu.flywheel.core.StitchedSprite;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.simibubi.create.AllPartialModels;
|
||||
|
@ -31,6 +30,7 @@ import net.minecraft.resources.ResourceLocation;
|
|||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends KineticBlockEntityRenderer<T> {
|
||||
|
@ -40,6 +40,8 @@ public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends Kinetic
|
|||
public static final StitchedSprite OAK_LOG_TEMPLATE = new StitchedSprite(new ResourceLocation("block/oak_log"));
|
||||
public static final StitchedSprite OAK_LOG_TOP_TEMPLATE = new StitchedSprite(new ResourceLocation("block/oak_log_top"));
|
||||
|
||||
private static final String[] LOG_SUFFIXES = new String[] { "_log", "_stem" };
|
||||
|
||||
protected final boolean large;
|
||||
|
||||
public WaterWheelRenderer(Context context, boolean large) {
|
||||
|
@ -59,9 +61,8 @@ public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends Kinetic
|
|||
protected SuperByteBuffer getRotatedModel(T be, BlockState state) {
|
||||
WaterWheelModelKey key = new WaterWheelModelKey(large, state, be.material);
|
||||
return CreateClient.BUFFER_CACHE.get(WATER_WHEEL, key, () -> {
|
||||
BakedModel model = WaterWheelRenderer.generateModel(key);
|
||||
BakedModel model = generateModel(key);
|
||||
BlockState state1 = key.state();
|
||||
// TODO waterwheels
|
||||
Direction dir;
|
||||
if (key.large()) {
|
||||
dir = Direction.fromAxisAndDirection(state1.getValue(LargeWaterWheelBlock.AXIS), AxisDirection.POSITIVE);
|
||||
|
@ -73,25 +74,24 @@ public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends Kinetic
|
|||
});
|
||||
}
|
||||
|
||||
public static PartialModel getTemplateModel(boolean large, boolean extension) {
|
||||
if (large) {
|
||||
if (extension) {
|
||||
return AllPartialModels.LARGE_WATER_WHEEL_EXTENSION;
|
||||
} else {
|
||||
return AllPartialModels.LARGE_WATER_WHEEL;
|
||||
}
|
||||
} else {
|
||||
return AllPartialModels.WATER_WHEEL;
|
||||
}
|
||||
}
|
||||
|
||||
public static BakedModel generateModel(WaterWheelModelKey key) {
|
||||
BakedModel template;
|
||||
if (key.large()) {
|
||||
boolean extension = key.state()
|
||||
.getOptionalValue(LargeWaterWheelBlock.EXTENSION)
|
||||
.orElse(false);
|
||||
BakedModel template = getTemplateModel(key.large(), extension).get();
|
||||
.getValue(LargeWaterWheelBlock.EXTENSION);
|
||||
if (extension) {
|
||||
template = AllPartialModels.LARGE_WATER_WHEEL_EXTENSION.get();
|
||||
} else {
|
||||
template = AllPartialModels.LARGE_WATER_WHEEL.get();
|
||||
}
|
||||
} else {
|
||||
template = AllPartialModels.WATER_WHEEL.get();
|
||||
}
|
||||
|
||||
BlockState planksBlockState = key.material();
|
||||
return generateModel(template, key.material());
|
||||
}
|
||||
|
||||
public static BakedModel generateModel(BakedModel template, BlockState planksBlockState) {
|
||||
Block planksBlock = planksBlockState.getBlock();
|
||||
ResourceLocation id = RegisteredObjects.getKeyOrThrow(planksBlock);
|
||||
String path = id.getPath();
|
||||
|
@ -103,7 +103,7 @@ public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends Kinetic
|
|||
|
||||
Map<TextureAtlasSprite, TextureAtlasSprite> map = new Reference2ReferenceOpenHashMap<>();
|
||||
map.put(OAK_PLANKS_TEMPLATE.get(), getSpriteOnSide(planksBlockState, Direction.UP));
|
||||
map.put(OAK_LOG_TEMPLATE.get(), getSpriteOnSide(logBlockState, Direction.NORTH));
|
||||
map.put(OAK_LOG_TEMPLATE.get(), getSpriteOnSide(logBlockState, Direction.SOUTH));
|
||||
map.put(OAK_LOG_TOP_TEMPLATE.get(), getSpriteOnSide(logBlockState, Direction.UP));
|
||||
|
||||
return BakedModelHelper.generateModel(template, map::get);
|
||||
|
@ -113,7 +113,7 @@ public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends Kinetic
|
|||
}
|
||||
|
||||
private static BlockState getLogBlockState(String namespace, String wood) {
|
||||
for (String suffix : new String[] { "_log", "_stem" }) {
|
||||
for (String suffix : LOG_SUFFIXES) {
|
||||
Optional<BlockState> state =
|
||||
ForgeRegistries.BLOCKS.getHolder(new ResourceLocation(namespace, wood + suffix))
|
||||
.map(Holder::value)
|
||||
|
@ -124,18 +124,28 @@ public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends Kinetic
|
|||
return Blocks.OAK_LOG.defaultBlockState();
|
||||
}
|
||||
|
||||
private static TextureAtlasSprite getSpriteOnSide(BlockState blockstate, Direction side) {
|
||||
BakedModel blockModel = Minecraft.getInstance()
|
||||
private static TextureAtlasSprite getSpriteOnSide(BlockState state, Direction side) {
|
||||
BakedModel model = Minecraft.getInstance()
|
||||
.getBlockRenderer()
|
||||
.getBlockModel(blockstate);
|
||||
if (blockModel == null)
|
||||
return null;
|
||||
@SuppressWarnings("deprecation")
|
||||
List<BakedQuad> quads = blockModel.getQuads(blockstate, side, new Random());
|
||||
if (quads.isEmpty())
|
||||
.getBlockModel(state);
|
||||
if (model == null)
|
||||
return null;
|
||||
Random random = new Random(42L);
|
||||
List<BakedQuad> quads = model.getQuads(state, side, random, EmptyModelData.INSTANCE);
|
||||
if (!quads.isEmpty()) {
|
||||
return quads.get(0)
|
||||
.getSprite();
|
||||
}
|
||||
random.setSeed(42L);
|
||||
quads = model.getQuads(state, null, random, EmptyModelData.INSTANCE);
|
||||
if (!quads.isEmpty()) {
|
||||
for (BakedQuad quad : quads) {
|
||||
if (quad.getDirection() == side) {
|
||||
return quad.getSprite();
|
||||
}
|
||||
}
|
||||
}
|
||||
return model.getParticleIcon(EmptyModelData.INSTANCE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -127,6 +127,8 @@ public class FilterItem extends Item implements MenuProvider {
|
|||
for (Tag inbt : attributes) {
|
||||
CompoundTag compound = (CompoundTag) inbt;
|
||||
ItemAttribute attribute = ItemAttribute.fromNBT(compound);
|
||||
if (attribute == null)
|
||||
continue;
|
||||
boolean inverted = compound.getBoolean("Inverted");
|
||||
if (count > 3) {
|
||||
list.add(Components.literal("- ...")
|
||||
|
@ -194,15 +196,19 @@ public class FilterItem extends Item implements MenuProvider {
|
|||
return test(world, stack, filter, true);
|
||||
}
|
||||
|
||||
private static boolean test(Level world, ItemStack stack, ItemStack filter, boolean matchNBT) {
|
||||
public static boolean test(Level world, ItemStack stack, ItemStack filter, boolean matchNBT) {
|
||||
if (filter.isEmpty())
|
||||
return true;
|
||||
|
||||
if (!(filter.getItem() instanceof FilterItem))
|
||||
return (matchNBT ? ItemHandlerHelper.canItemStacksStack(filter, stack) : ItemStack.isSame(filter, stack));
|
||||
return testDirect(stack, filter, matchNBT);
|
||||
|
||||
boolean defaults = !filter.hasTag();
|
||||
|
||||
if (defaults) {
|
||||
return testDirect(filter, stack, matchNBT);
|
||||
}
|
||||
|
||||
if (AllItems.FILTER.get() == filter.getItem()) {
|
||||
ItemStackHandler filterItems = getFilterItems(filter);
|
||||
boolean respectNBT = defaults ? false
|
||||
|
@ -211,24 +217,32 @@ public class FilterItem extends Item implements MenuProvider {
|
|||
boolean blacklist = defaults ? false
|
||||
: filter.getTag()
|
||||
.getBoolean("Blacklist");
|
||||
boolean isEmpty = true;
|
||||
for (int slot = 0; slot < filterItems.getSlots(); slot++) {
|
||||
ItemStack stackInSlot = filterItems.getStackInSlot(slot);
|
||||
if (stackInSlot.isEmpty())
|
||||
continue;
|
||||
isEmpty = false;
|
||||
boolean matches = test(world, stack, stackInSlot, respectNBT);
|
||||
if (matches)
|
||||
return !blacklist;
|
||||
}
|
||||
if (isEmpty) {
|
||||
return testDirect(filter, stack, matchNBT);
|
||||
}
|
||||
return blacklist;
|
||||
}
|
||||
|
||||
if (AllItems.ATTRIBUTE_FILTER.get() == filter.getItem()) {
|
||||
WhitelistMode whitelistMode = WhitelistMode.values()[defaults ? 0
|
||||
: filter.getTag()
|
||||
.getInt("WhitelistMode")];
|
||||
ListTag attributes = defaults ? new ListTag()
|
||||
: filter.getTag()
|
||||
.getList("MatchedAttributes", Tag.TAG_COMPOUND);
|
||||
if (attributes.isEmpty()) {
|
||||
return testDirect(filter, stack, matchNBT);
|
||||
}
|
||||
WhitelistMode whitelistMode = WhitelistMode.values()[defaults ? 0
|
||||
: filter.getTag()
|
||||
.getInt("WhitelistMode")];
|
||||
for (Tag inbt : attributes) {
|
||||
CompoundTag compound = (CompoundTag) inbt;
|
||||
ItemAttribute attribute = ItemAttribute.fromNBT(compound);
|
||||
|
@ -270,7 +284,7 @@ public class FilterItem extends Item implements MenuProvider {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static boolean test(Level world, FluidStack stack, ItemStack filter, boolean matchNBT) {
|
||||
public static boolean test(Level world, FluidStack stack, ItemStack filter, boolean matchNBT) {
|
||||
if (filter.isEmpty())
|
||||
return true;
|
||||
if (stack.isEmpty())
|
||||
|
@ -313,4 +327,12 @@ public class FilterItem extends Item implements MenuProvider {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static boolean testDirect(ItemStack filter, ItemStack stack, boolean matchNBT) {
|
||||
if (matchNBT) {
|
||||
return ItemHandlerHelper.canItemStacksStack(filter, stack);
|
||||
} else {
|
||||
return ItemStack.isSame(filter, stack);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.util.function.Predicate;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.simibubi.create.AllRecipeTypes;
|
||||
import com.simibubi.create.content.contraptions.processing.InWorldProcessing;
|
||||
|
@ -78,6 +79,7 @@ public interface ItemAttribute {
|
|||
return attributeType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static ItemAttribute fromNBT(CompoundTag nbt) {
|
||||
for (ItemAttribute itemAttribute : types)
|
||||
if (itemAttribute.canRead(nbt))
|
||||
|
|
Loading…
Reference in a new issue