Skip to content

Commit

Permalink
Merge branch 'architectury-1.20' into architectury-1.20.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	fabric/src/main/java/com/unlikepaladin/pfm/mixin/fabric/PFMModResourcePackCreatorMixin.java
#	forge/src/main/java/com/unlikepaladin/pfm/compat/imm_ptl/forge/shape/BlockPortalShape.java
#	forge/src/main/java/com/unlikepaladin/pfm/forge/PaladinFurnitureModForge.java
#	forge/src/main/java/com/unlikepaladin/pfm/registry/forge/NetworkRegistryForge.java
  • Loading branch information
UnlikePaladin committed Dec 29, 2023
2 parents 42e2fa9 + b0c19eb commit c89e82b
Show file tree
Hide file tree
Showing 445 changed files with 6,928 additions and 3,558 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
}

List<ChairEntity> active = world.getEntitiesByClass(ChairEntity.class, new Box(pos), Entity::hasPassengers);
if (active == null)
return ActionResult.FAIL;

List<Entity> hasPassenger = new ArrayList<>();
active.forEach(chairEntity -> hasPassenger.add(chairEntity.getFirstPassenger()));
if (!active.isEmpty() && hasPassenger.stream().anyMatch(Entity::isPlayer)) {
Expand Down Expand Up @@ -163,10 +166,10 @@ public ActionResult sitEntity(World world, BlockPos pos, BlockState state, Entit
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
super.onEntityCollision(state, world, pos, entity);
List<ChairEntity> active = world.getEntitiesByClass(ChairEntity.class, new Box(pos), Entity::hasPassengers);
if (!active.isEmpty())
if (active == null || !active.isEmpty())
return;

if (entity instanceof PlayerEntity || entity instanceof IronGolemEntity || entity instanceof AbstractMinecartEntity || entity.hasVehicle() || !(entity instanceof LivingEntity)) {
if (entity instanceof PlayerEntity || entity instanceof IronGolemEntity || entity instanceof AbstractMinecartEntity || entity.hasVehicle() || !(entity instanceof LivingEntity) || entity instanceof ChairEntity) {
return;
}
if (!PaladinFurnitureMod.getPFMConfig().doMobsSitOnChairs())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static VoxelShape rotateShape(Direction from, Direction to, VoxelShape sh
final static VoxelShape TABLE_CLASSIC_SOUTH_WEST_LEG = createCuboidShape(2, 0, 12, 4, 15, 14);
final static VoxelShape TABLE_CLASSIC_SOUTH_EAST_LEG = createCuboidShape(12, 0, 12, 14, 15, 14);

//Cursed I know
// Cursed I know
final static Map<String, VoxelShape> VOXEL_SHAPES = new HashMap<>();
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static VoxelShape rotateShape(Direction from, Direction to, VoxelShape sh
final static VoxelShape LOG_TABLE_ONE_SOUTH = rotateShape(Direction.NORTH, Direction.SOUTH, LOG_TABLE_ONE);
final static VoxelShape LOG_TABLE_ONE_EAST = rotateShape(Direction.NORTH, Direction.EAST, LOG_TABLE_ONE);
final static VoxelShape LOG_TABLE_EAST = rotateShape(Direction.NORTH, Direction.EAST, LOG_TABLE);
//Cursed I know
// Cursed I know
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext context) {
Direction dir = state.get(FACING);
boolean left = isTable(view, pos, dir.rotateYCounterclockwise(), dir);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.unlikepaladin.pfm.blocks;

import com.unlikepaladin.pfm.blocks.blockentities.PFMBedBlockEntity;
import com.unlikepaladin.pfm.client.PFMBuiltinItemRendererExtension;
import com.unlikepaladin.pfm.data.FurnitureBlock;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.enums.BedPart;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.pathing.NavigationType;
Expand Down Expand Up @@ -36,7 +39,7 @@

import static com.unlikepaladin.pfm.blocks.LogTableBlock.rotateShape;

public class SimpleBedBlock extends BedBlock implements DyeableFurnitureBlock {
public class SimpleBedBlock extends BedBlock implements DyeableFurnitureBlock, PFMBuiltinItemRendererExtension {
private static final List<FurnitureBlock> SIMPLE_BEDS = new ArrayList<>();
private final DyeColor color;
public SimpleBedBlock(DyeColor color, Settings settings) {
Expand Down Expand Up @@ -210,4 +213,9 @@ public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos po
public DyeColor getPFMColor() {
return color;
}

@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new PFMBedBlockEntity(pos, state, this.color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
import net.minecraft.world.World;

public class BathtubBlockEntity extends BedBlockEntity {
private final BlockEntityType<?> type;
public BathtubBlockEntity(BlockPos pos, BlockState state) {
super(pos, state, DyeColor.WHITE);
this.type = BlockEntities.BATHTUB_BLOCK_ENTITY;
}

@Override
public BlockEntityType<?> getType() {
return type;
return BlockEntities.BATHTUB_BLOCK_ENTITY;
}

private int fillTimer = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.unlikepaladin.pfm.blocks.blockentities;

import com.unlikepaladin.pfm.registry.BlockEntities;
import net.minecraft.block.BedBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BedBlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.DyeColor;
import net.minecraft.util.math.BlockPos;

public class PFMBedBlockEntity extends BedBlockEntity implements DyeableFurnitureBlockEntity<PFMBedBlockEntity> {
public PFMBedBlockEntity(BlockPos pos, BlockState state, DyeColor color) {
super(pos, state, color);
}

public PFMBedBlockEntity(BlockPos pos, BlockState state) {
super(pos, state);
}

@Override
public void setPFMColor(DyeColor color) {
this.setColor(color);
}

@Override
public DyeColor getPFMColor() {
return getColor();
}

@Override
public NbtCompound writeColor(NbtCompound nbt) {
nbt.putString("color", getColor().asString());
return nbt;
}

@Override
public PFMBedBlockEntity getEntity() {
return this;
}

@Override
public BlockEntityType<?> getType() {
return BlockEntities.BED_BLOCK_ENTITY;
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,50 @@
package com.unlikepaladin.pfm.blocks.models;

import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.blocks.KitchenCounterBlock;
import com.unlikepaladin.pfm.blocks.LogStoolBlock;
import com.unlikepaladin.pfm.blocks.SimpleBedBlock;
import com.unlikepaladin.pfm.data.materials.BlockType;
import com.unlikepaladin.pfm.data.materials.StoneVariant;
import com.unlikepaladin.pfm.data.materials.VariantBase;
import com.unlikepaladin.pfm.data.materials.WoodVariant;
import com.unlikepaladin.pfm.registry.PaladinFurnitureModBlocksItems;
import com.unlikepaladin.pfm.runtime.data.PFMRecipeProvider;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BedBlockEntity;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.TexturedRenderLayers;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.render.model.ModelBakeSettings;
import net.minecraft.client.render.model.json.ModelOverrideList;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Pair;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import net.minecraft.util.math.random.Random;
import java.util.*;

public abstract class AbstractBakedModel implements BakedModel {
protected final ModelBakeSettings settings;
private final Sprite frame;
private final Map<String,BakedModel> bakedModels;
public AbstractBakedModel(Sprite frame, ModelBakeSettings settings, Map<String, BakedModel> bakedModels) {
this.frame = frame;
private final List<BakedModel> templateBakedModels;
public AbstractBakedModel(ModelBakeSettings settings, List<BakedModel> templateBakedModels) {
this.settings = settings;
this.bakedModels = bakedModels;
this.templateBakedModels = templateBakedModels;
}

public Map<String, BakedModel> getBakedModels() {
return bakedModels;
public List<BakedModel> getTemplateBakedModels() {
return templateBakedModels;
}

@Override
Expand Down Expand Up @@ -54,18 +72,112 @@ public boolean isBuiltin() {
return false;
}

@Override
public Sprite getParticleSprite() {
return frame;
}

@Override
public ModelTransformation getTransformation() {
return ModelTransformation.NONE;
return templateBakedModels.get(0).getTransformation();
}

@Override
public ModelOverrideList getOverrides() {
return ModelOverrideList.EMPTY;
}

Map<Block, VariantBase<?>> blockVariantMap = new HashMap<>();
protected VariantBase<?> getVariant(BlockState state) {
VariantBase<?> variant;
if (blockVariantMap.containsKey(state.getBlock())) {
variant = blockVariantMap.get(state.getBlock());
} else {
variant = PaladinFurnitureMod.furnitureEntryMap.get(state.getBlock().getClass()).getVariantFromEntry(state.getBlock());
blockVariantMap.put(state.getBlock(), variant);
}
return variant;
}


private final Map<BlockItem, BlockState> blockItemBlockStateMap = new HashMap<>();
/**
Accepts an ItemStack, a BlockState, a Block or a BlockItem
*/
public <T> List<Sprite> getSpriteList(T element) {
if (element instanceof BlockState) {
BlockState state = (BlockState) element;
return getSpriteFromState(state);
}
else if (element instanceof BlockItem) {
BlockItem blockItem = (BlockItem) element;
if (blockItemBlockStateMap.containsKey(blockItem))
return getSpriteFromState(blockItemBlockStateMap.get(blockItem));

BlockState state = blockItem.getBlock().getDefaultState();
blockItemBlockStateMap.put(blockItem, state);
return getSpriteFromState(state);
} else if (element instanceof Block) {
Block block = (Block) element;
if (spriteList.containsKey(block))
return spriteList.get(block);

BlockState state = block.getDefaultState();
return getSpriteFromState(state);
} else if (element instanceof ItemStack && ((ItemStack) element).getItem() instanceof BlockItem) {
BlockItem blockItem = (BlockItem)((ItemStack) element).getItem();
if (blockItemBlockStateMap.containsKey(blockItem))
return getSpriteFromState(blockItemBlockStateMap.get(blockItem));

BlockState state = blockItem.getBlock().getDefaultState();
blockItemBlockStateMap.put(blockItem, state);
return getSpriteFromState(state);
} else if (element == null) {
return Collections.singletonList(getTemplateBakedModels().get(0).getParticleSprite());
} else {
PaladinFurnitureMod.GENERAL_LOGGER.error("Invalid element for sprite list method");
}
return Collections.singletonList(getTemplateBakedModels().get(0).getParticleSprite());
}
protected List<Sprite> getBedSprites(DyeColor color, BlockState state) {
List<Sprite> list = new ArrayList<>(3);
VariantBase<?> variant = getVariant(state);

return list;
}
private final Map<Block, List<Sprite>> spriteList = new HashMap<>();
private List<Sprite> getSpriteFromState(BlockState state) {
if (spriteList.containsKey(state.getBlock()))
return spriteList.get(state.getBlock());

VariantBase<?> variant = getVariant(state);
boolean stripped = state.getBlock().getTranslationKey().contains("stripped");
List<Sprite> list = new ArrayList<>(3);
if (state.getBlock() instanceof SimpleBedBlock) {
DyeColor color = ModelHelper.getColor(Registries.BLOCK.getId(state.getBlock()));
SpriteIdentifier mainTexture = new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, variant.getTexture(BlockType.PLANKS));
SpriteIdentifier spriteIdentifier = TexturedRenderLayers.BED_TEXTURES[color.getId()];
list.add(mainTexture.getSprite());
list.add(spriteIdentifier.getSprite());
} else if (state.getBlock() instanceof LogStoolBlock) {
SpriteIdentifier mainTexture = stripped ? new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, variant.getTexture(BlockType.STRIPPED_LOG)) : new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, variant.getTexture(BlockType.LOG));
SpriteIdentifier secondTexture = stripped ? new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, variant.getTexture(BlockType.STRIPPED_LOG_TOP)) : new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, variant.getTexture(BlockType.LOG_TOP));
list.add(mainTexture.getSprite());
list.add(secondTexture.getSprite());
} else if (!state.getBlock().getTranslationKey().contains("_raw_")) {
SpriteIdentifier mainTexture = stripped ? new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, variant.getTexture(BlockType.STRIPPED_LOG)) : new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, variant.getTexture(BlockType.PRIMARY));
SpriteIdentifier secondTexture = stripped ? new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, variant.getTexture(BlockType.PRIMARY)) : new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, variant.getTexture(BlockType.SECONDARY));
list.add(mainTexture.getSprite());
list.add(secondTexture.getSprite());
} else {
SpriteIdentifier mainTexture = stripped ? new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, variant.getTexture(BlockType.STRIPPED_LOG)) : new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, variant.getTexture(BlockType.SECONDARY));
list.add(mainTexture.getSprite());
list.add(mainTexture.getSprite());
}
boolean isKitchen = state.getBlock().getTranslationKey().contains("kitchen_");
if (isKitchen && !(variant instanceof WoodVariant)) {
Pair<Block, Block> counterMaterials = PFMRecipeProvider.getCounterMaterials(variant);
SpriteIdentifier mainTexture = new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, ModelHelper.getTextureId(counterMaterials.getLeft()));
SpriteIdentifier secondTexture = new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, ModelHelper.getTextureId(counterMaterials.getRight()));
list.set(0, mainTexture.getSprite());
list.set(1, secondTexture.getSprite());
}
spriteList.put(state.getBlock(), list);
return list;
}
}
Loading

0 comments on commit c89e82b

Please sign in to comment.