Merge branch 'mc1.18/0.5.1' of https://github.com/Creators-of-Create/Create-Concealed into mc1.18/0.5.1

This commit is contained in:
simibubi 2023-05-12 21:51:37 +02:00
commit 5fc755eb16
4 changed files with 67 additions and 34 deletions

View file

@ -42,7 +42,6 @@ public class WaterWheelInstance<T extends WaterWheelBlockEntity> extends CutoutR
return getRotatingMaterial().model(key, () -> { return getRotatingMaterial().model(key, () -> {
BakedModel model = WaterWheelRenderer.generateModel(key); BakedModel model = WaterWheelRenderer.generateModel(key);
BlockState state = key.state(); BlockState state = key.state();
// TODO waterwheels
Direction dir; Direction dir;
if (key.large()) { if (key.large()) {
dir = Direction.fromAxisAndDirection(state.getValue(LargeWaterWheelBlock.AXIS), AxisDirection.POSITIVE); dir = Direction.fromAxisAndDirection(state.getValue(LargeWaterWheelBlock.AXIS), AxisDirection.POSITIVE);

View file

@ -5,7 +5,6 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Random; import java.util.Random;
import com.jozufozu.flywheel.core.PartialModel;
import com.jozufozu.flywheel.core.StitchedSprite; import com.jozufozu.flywheel.core.StitchedSprite;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.simibubi.create.AllPartialModels; 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.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.model.data.EmptyModelData;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends KineticBlockEntityRenderer<T> { 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_TEMPLATE = new StitchedSprite(new ResourceLocation("block/oak_log"));
public static final StitchedSprite OAK_LOG_TOP_TEMPLATE = new StitchedSprite(new ResourceLocation("block/oak_log_top")); 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; protected final boolean large;
public WaterWheelRenderer(Context context, 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) { protected SuperByteBuffer getRotatedModel(T be, BlockState state) {
WaterWheelModelKey key = new WaterWheelModelKey(large, state, be.material); WaterWheelModelKey key = new WaterWheelModelKey(large, state, be.material);
return CreateClient.BUFFER_CACHE.get(WATER_WHEEL, key, () -> { return CreateClient.BUFFER_CACHE.get(WATER_WHEEL, key, () -> {
BakedModel model = WaterWheelRenderer.generateModel(key); BakedModel model = generateModel(key);
BlockState state1 = key.state(); BlockState state1 = key.state();
// TODO waterwheels
Direction dir; Direction dir;
if (key.large()) { if (key.large()) {
dir = Direction.fromAxisAndDirection(state1.getValue(LargeWaterWheelBlock.AXIS), AxisDirection.POSITIVE); 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) { public static BakedModel generateModel(WaterWheelModelKey key) {
if (large) { BakedModel template;
if (key.large()) {
boolean extension = key.state()
.getValue(LargeWaterWheelBlock.EXTENSION);
if (extension) { if (extension) {
return AllPartialModels.LARGE_WATER_WHEEL_EXTENSION; template = AllPartialModels.LARGE_WATER_WHEEL_EXTENSION.get();
} else { } else {
return AllPartialModels.LARGE_WATER_WHEEL; template = AllPartialModels.LARGE_WATER_WHEEL.get();
} }
} else { } else {
return AllPartialModels.WATER_WHEEL; template = AllPartialModels.WATER_WHEEL.get();
} }
return generateModel(template, key.material());
} }
public static BakedModel generateModel(WaterWheelModelKey key) { public static BakedModel generateModel(BakedModel template, BlockState planksBlockState) {
boolean extension = key.state()
.getOptionalValue(LargeWaterWheelBlock.EXTENSION)
.orElse(false);
BakedModel template = getTemplateModel(key.large(), extension).get();
BlockState planksBlockState = key.material();
Block planksBlock = planksBlockState.getBlock(); Block planksBlock = planksBlockState.getBlock();
ResourceLocation id = RegisteredObjects.getKeyOrThrow(planksBlock); ResourceLocation id = RegisteredObjects.getKeyOrThrow(planksBlock);
String path = id.getPath(); String path = id.getPath();
@ -103,7 +103,7 @@ public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends Kinetic
Map<TextureAtlasSprite, TextureAtlasSprite> map = new Reference2ReferenceOpenHashMap<>(); Map<TextureAtlasSprite, TextureAtlasSprite> map = new Reference2ReferenceOpenHashMap<>();
map.put(OAK_PLANKS_TEMPLATE.get(), getSpriteOnSide(planksBlockState, Direction.UP)); 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)); map.put(OAK_LOG_TOP_TEMPLATE.get(), getSpriteOnSide(logBlockState, Direction.UP));
return BakedModelHelper.generateModel(template, map::get); 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) { private static BlockState getLogBlockState(String namespace, String wood) {
for (String suffix : new String[] { "_log", "_stem" }) { for (String suffix : LOG_SUFFIXES) {
Optional<BlockState> state = Optional<BlockState> state =
ForgeRegistries.BLOCKS.getHolder(new ResourceLocation(namespace, wood + suffix)) ForgeRegistries.BLOCKS.getHolder(new ResourceLocation(namespace, wood + suffix))
.map(Holder::value) .map(Holder::value)
@ -124,18 +124,28 @@ public class WaterWheelRenderer<T extends WaterWheelBlockEntity> extends Kinetic
return Blocks.OAK_LOG.defaultBlockState(); return Blocks.OAK_LOG.defaultBlockState();
} }
private static TextureAtlasSprite getSpriteOnSide(BlockState blockstate, Direction side) { private static TextureAtlasSprite getSpriteOnSide(BlockState state, Direction side) {
BakedModel blockModel = Minecraft.getInstance() BakedModel model = Minecraft.getInstance()
.getBlockRenderer() .getBlockRenderer()
.getBlockModel(blockstate); .getBlockModel(state);
if (blockModel == null) if (model == null)
return null; return null;
@SuppressWarnings("deprecation") Random random = new Random(42L);
List<BakedQuad> quads = blockModel.getQuads(blockstate, side, new Random()); List<BakedQuad> quads = model.getQuads(state, side, random, EmptyModelData.INSTANCE);
if (quads.isEmpty()) if (!quads.isEmpty()) {
return null; return quads.get(0)
return quads.get(0) .getSprite();
.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);
} }
} }

View file

@ -127,6 +127,8 @@ public class FilterItem extends Item implements MenuProvider {
for (Tag inbt : attributes) { for (Tag inbt : attributes) {
CompoundTag compound = (CompoundTag) inbt; CompoundTag compound = (CompoundTag) inbt;
ItemAttribute attribute = ItemAttribute.fromNBT(compound); ItemAttribute attribute = ItemAttribute.fromNBT(compound);
if (attribute == null)
continue;
boolean inverted = compound.getBoolean("Inverted"); boolean inverted = compound.getBoolean("Inverted");
if (count > 3) { if (count > 3) {
list.add(Components.literal("- ...") list.add(Components.literal("- ...")
@ -194,15 +196,19 @@ public class FilterItem extends Item implements MenuProvider {
return test(world, stack, filter, true); 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()) if (filter.isEmpty())
return true; return true;
if (!(filter.getItem() instanceof FilterItem)) if (!(filter.getItem() instanceof FilterItem))
return (matchNBT ? ItemHandlerHelper.canItemStacksStack(filter, stack) : ItemStack.isSame(filter, stack)); return testDirect(filter, stack, matchNBT);
boolean defaults = !filter.hasTag(); boolean defaults = !filter.hasTag();
if (defaults) {
return testDirect(filter, stack, matchNBT);
}
if (AllItems.FILTER.get() == filter.getItem()) { if (AllItems.FILTER.get() == filter.getItem()) {
ItemStackHandler filterItems = getFilterItems(filter); ItemStackHandler filterItems = getFilterItems(filter);
boolean respectNBT = defaults ? false boolean respectNBT = defaults ? false
@ -211,24 +217,32 @@ public class FilterItem extends Item implements MenuProvider {
boolean blacklist = defaults ? false boolean blacklist = defaults ? false
: filter.getTag() : filter.getTag()
.getBoolean("Blacklist"); .getBoolean("Blacklist");
boolean isEmpty = true;
for (int slot = 0; slot < filterItems.getSlots(); slot++) { for (int slot = 0; slot < filterItems.getSlots(); slot++) {
ItemStack stackInSlot = filterItems.getStackInSlot(slot); ItemStack stackInSlot = filterItems.getStackInSlot(slot);
if (stackInSlot.isEmpty()) if (stackInSlot.isEmpty())
continue; continue;
isEmpty = false;
boolean matches = test(world, stack, stackInSlot, respectNBT); boolean matches = test(world, stack, stackInSlot, respectNBT);
if (matches) if (matches)
return !blacklist; return !blacklist;
} }
if (isEmpty) {
return testDirect(filter, stack, matchNBT);
}
return blacklist; return blacklist;
} }
if (AllItems.ATTRIBUTE_FILTER.get() == filter.getItem()) { if (AllItems.ATTRIBUTE_FILTER.get() == filter.getItem()) {
WhitelistMode whitelistMode = WhitelistMode.values()[defaults ? 0
: filter.getTag()
.getInt("WhitelistMode")];
ListTag attributes = defaults ? new ListTag() ListTag attributes = defaults ? new ListTag()
: filter.getTag() : filter.getTag()
.getList("MatchedAttributes", Tag.TAG_COMPOUND); .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) { for (Tag inbt : attributes) {
CompoundTag compound = (CompoundTag) inbt; CompoundTag compound = (CompoundTag) inbt;
ItemAttribute attribute = ItemAttribute.fromNBT(compound); ItemAttribute attribute = ItemAttribute.fromNBT(compound);
@ -270,7 +284,7 @@ public class FilterItem extends Item implements MenuProvider {
return false; 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()) if (filter.isEmpty())
return true; return true;
if (stack.isEmpty()) if (stack.isEmpty())
@ -313,4 +327,12 @@ public class FilterItem extends Item implements MenuProvider {
return false; 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);
}
}
} }

View file

@ -10,6 +10,7 @@ import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import com.simibubi.create.AllRecipeTypes; import com.simibubi.create.AllRecipeTypes;
import com.simibubi.create.content.contraptions.processing.InWorldProcessing; import com.simibubi.create.content.contraptions.processing.InWorldProcessing;
@ -78,6 +79,7 @@ public interface ItemAttribute {
return attributeType; return attributeType;
} }
@Nullable
static ItemAttribute fromNBT(CompoundTag nbt) { static ItemAttribute fromNBT(CompoundTag nbt) {
for (ItemAttribute itemAttribute : types) for (ItemAttribute itemAttribute : types)
if (itemAttribute.canRead(nbt)) if (itemAttribute.canRead(nbt))