Skip to content

Commit

Permalink
fix: addressed issues with the parachest entity (TeamGalacticraft#403)
Browse files Browse the repository at this point in the history
* fix: correctly set ParachestEntity parachute color and fixed parachest texture/model issues

* refactor: changed instances of 'ParaChest' to 'Parachest' for consistency
  • Loading branch information
Roelymole authored Jan 31, 2025
1 parent 6a8940b commit f8f2a65
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public interface CelestialHandler {
* the world with. Return null for no spawn
*/
@Nullable
Vec3 getParaChestSpawnLocation(Level world, Player player, RandomSource rand);
Vec3 getParachestSpawnLocation(Level world, Player player, RandomSource rand);

/**
* This method is used to determine if a player will open parachute upon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public class DefaultCelestialHandler implements CelestialHandler {
@Override
public @Nullable Vec3 getParaChestSpawnLocation(Level world, Player player, RandomSource rand) {
public @Nullable Vec3 getParachestSpawnLocation(Level world, Player player, RandomSource rand) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public class OverworldHandler implements CelestialHandler {
@Override
public @Nullable Vec3 getParaChestSpawnLocation(Level world, Player player, RandomSource rand) {
public @Nullable Vec3 getParachestSpawnLocation(Level world, Player player, RandomSource rand) {
final double x = (rand.nextDouble() * 2 - 1.0D) * 5.0D;
final double z = (rand.nextDouble() * 2 - 1.0D) * 5.0D;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

package dev.galacticraft.mod.client.model;

import dev.galacticraft.mod.content.block.special.ParaChestBlock;
import dev.galacticraft.mod.content.block.special.ParachestBlock;
import net.fabricmc.fabric.api.renderer.v1.model.WrapperBakedModel;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.client.multiplayer.ClientLevel;
Expand All @@ -46,28 +46,28 @@
import java.util.Map;
import java.util.function.Supplier;

public class ParaChestBakedModel implements BakedModel, WrapperBakedModel {
private final ParaChestOverride itemOverride;
public class ParachestBakedModel implements BakedModel, WrapperBakedModel {
private final ParachestOverride itemOverride;
private final BakedModel parent;
private final Map<DyeColor, BakedModel> bakedChutes;
private final DyeColor defaultColor;

public ParaChestBakedModel(BakedModel parent, Map<DyeColor, BakedModel> bakedChutes) {
public ParachestBakedModel(BakedModel parent, Map<DyeColor, BakedModel> bakedChutes) {
this(parent, bakedChutes, DyeColor.WHITE);
}

public ParaChestBakedModel(BakedModel parent, Map<DyeColor, BakedModel> bakedChutes, DyeColor defaultColor) {
public ParachestBakedModel(BakedModel parent, Map<DyeColor, BakedModel> bakedChutes, DyeColor defaultColor) {
this.parent = parent;
this.bakedChutes = bakedChutes;
this.defaultColor = defaultColor;
this.itemOverride = new ParaChestOverride();
this.itemOverride = new ParachestOverride();
}

@Override
public List<BakedQuad> getQuads(@Nullable BlockState blockState, @Nullable Direction direction, RandomSource randomSource) {
List<BakedQuad> quads = new ArrayList<>(parent.getQuads(blockState, direction, randomSource));
if (blockState != null)
quads.addAll(bakedChutes.get(blockState.getValue(ParaChestBlock.COLOR)).getQuads(blockState, direction, randomSource));
quads.addAll(bakedChutes.get(blockState.getValue(ParachestBlock.COLOR)).getQuads(blockState, direction, randomSource));
else
quads.addAll(bakedChutes.get(defaultColor).getQuads(blockState, direction, randomSource));
return quads;
Expand Down Expand Up @@ -124,8 +124,8 @@ public BakedModel getWrappedModel() {
return parent;
}

public class ParaChestOverride extends ItemOverrides {
public ParaChestOverride() {
public class ParachestOverride extends ItemOverrides {
public ParachestOverride() {
super(null, null, Collections.emptyList());
}

Expand All @@ -134,9 +134,9 @@ public ParaChestOverride() {
public BakedModel resolve(BakedModel model, ItemStack stack, @Nullable ClientLevel level, @Nullable LivingEntity entity, int seed) {
DyeColor dyeColor = stack.get(DataComponents.BASE_COLOR);
if (dyeColor != null) {
return new ParaChestBakedModel(ParaChestBakedModel.this.parent, ParaChestBakedModel.this.bakedChutes, dyeColor);
return new ParachestBakedModel(ParachestBakedModel.this.parent, ParachestBakedModel.this.bakedChutes, dyeColor);
}
return ParaChestBakedModel.this.parent.getOverrides().resolve(model, stack, level, entity, seed);
return ParachestBakedModel.this.parent.getOverrides().resolve(model, stack, level, entity, seed);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ public BakedModel bake(ModelBaker baker, Function<Material, TextureAtlasSprite>
chutes.forEach((color, unbakedModel) -> {
bakedChutes.put(color, unbakedModel.bake(baker, textureGetter, state));
});
return new ParaChestBakedModel(parentModel.bake(baker, textureGetter, state), bakedChutes);
return new ParachestBakedModel(parentModel.bake(baker, textureGetter, state), bakedChutes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

public class ParachestRenderer extends EntityRenderer<ParachestEntity> {

public static final ResourceLocation TEXTURE = Constant.id("textures/model/parachest.png");
public static final ResourceLocation TEXTURE = Constant.id("textures/block/parachest.png");

public ParachestModel parachute;
private ModelPart chest;
Expand All @@ -48,20 +48,19 @@ public ParachestRenderer(EntityRendererProvider.Context context) {
this.shadowRadius = 1F;
this.chest = context.bakeLayer(ModelLayers.CHEST);
this.parachute = new ParachestModel(context.bakeLayer(GCEntityModelLayer.PARACHEST));

}



@Override
public void render(ParachestEntity entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource buffer, int packedLight) {
this.parachute.setupAnim(entity, 0F, 0F, 0F, 0F, 0F);
poseStack.translate(-0.5F, 0F, -0.5F);
this.chest.render(poseStack, buffer.getBuffer(RenderType.entityCutoutNoCull(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY);
poseStack.translate(-0.0625F, 0F, 0.375F);
this.parachute.renderToBuffer(poseStack, buffer.getBuffer(RenderType.entityCutoutNoCull(getTextureLocation(entity))), packedLight, OverlayTexture.NO_OVERLAY);
}

@Override
public ResourceLocation getTextureLocation(ParachestEntity entity) {
return Constant.id("textures/model/parachute/" + entity.color.getName() + ".png");
return Constant.id("textures/model/parachute/" + entity.getColor().getName() + ".png");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class GCBlockEntityTypes {
// ROCKETS
public static final BlockEntityType<LaunchPadBlockEntity> LAUNCH_PAD = BlockEntityType.Builder.of(LaunchPadBlockEntity::new, GCBlocks.ROCKET_LAUNCH_PAD, GCBlocks.FUELING_PAD).build();
public static final BlockEntityType<FuelLoaderBlockEntity> FUEL_LOADER = BlockEntityType.Builder.of(FuelLoaderBlockEntity::new, GCBlocks.FUEL_LOADER).build();
public static final BlockEntityType<ParaChestBlockEntity> PARACHEST = BlockEntityType.Builder.of(ParaChestBlockEntity::new, GCBlocks.PARACHEST).build();
public static final BlockEntityType<ParachestBlockEntity> PARACHEST = BlockEntityType.Builder.of(ParachestBlockEntity::new, GCBlocks.PARACHEST).build();

// MISC
public static final BlockEntityType<SolarPanelPartBlockEntity> SOLAR_PANEL_PART = BlockEntityType.Builder.of(SolarPanelPartBlockEntity::new, GCBlocks.SOLAR_PANEL_PART).build();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/galacticraft/mod/content/GCBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public class GCBlocks {
public static final Block FUELING_PAD = BLOCKS.register(Constant.Block.FUELING_PAD, new FuelPadBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_GRAY).instrument(NoteBlockInstrument.BASEDRUM).strength(1.5F, 10.0F).requiresCorrectToolForDrops()));
public static final Block ROCKET_LAUNCH_PAD = BLOCKS.register(Constant.Block.ROCKET_LAUNCH_PAD, new LaunchPadBlock(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_LIGHT_GRAY).instrument(NoteBlockInstrument.BASEDRUM).strength(1.5F, 10.0F).requiresCorrectToolForDrops()));
public static final Block ROCKET_WORKBENCH = BLOCKS.register(Constant.Block.ROCKET_WORKBENCH, new RocketWorkbench(BlockBehaviour.Properties.of().mapColor(MapColor.COLOR_GRAY).instrument(NoteBlockInstrument.BASEDRUM).strength(1.5F, 6.0F)));
public static final Block PARACHEST = BLOCKS.registerWithItem(Constant.Block.PARACHEST, new ParaChestBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.CHEST)));
public static final Block PARACHEST = BLOCKS.registerWithItem(Constant.Block.PARACHEST, new ParachestBlock(BlockBehaviour.Properties.ofFullCopy(Blocks.CHEST)));

// LIGHT PANELS
public static final Block SQUARE_LIGHT_PANEL = BLOCKS.register(Constant.Block.SQUARE_LIGHT_PANEL, new LightPanelBlock(BlockBehaviour.Properties.of().mapColor(MapColor.METAL)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@
import org.jetbrains.annotations.Nullable;

@SuppressWarnings("UnstableApiUsage")
public class ParaChestBlockEntity extends RandomizableContainerBlockEntity implements SidedStorageBlockEntity, ExtendedScreenHandlerFactory<ParachestMenu.OpeningData>, ScalableFuelLevel {
public class ParachestBlockEntity extends RandomizableContainerBlockEntity implements SidedStorageBlockEntity, ExtendedScreenHandlerFactory<ParachestMenu.OpeningData>, ScalableFuelLevel {

public final SingleFluidStorage tank = SingleFluidStorage.withFixedCapacity(FluidConstants.BUCKET * 5, () -> {
});
private NonNullList<ItemStack> inventory = NonNullList.withSize(3, ItemStack.EMPTY);

public ParaChestBlockEntity(BlockPos blockPos, BlockState blockState) {
public ParachestBlockEntity(BlockPos blockPos, BlockState blockState) {
super(GCBlockEntityTypes.PARACHEST, blockPos, blockState);
}

Expand Down Expand Up @@ -128,4 +128,4 @@ public void tick() {
public ParachestMenu.OpeningData getScreenOpeningData(ServerPlayer player) {
return new ParachestMenu.OpeningData(this.getBlockPos());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import dev.galacticraft.mod.content.GCBlockEntityTypes;
import dev.galacticraft.mod.content.GCStats;
import dev.galacticraft.mod.content.block.GCBlock;
import dev.galacticraft.mod.content.block.entity.ParaChestBlockEntity;
import dev.galacticraft.mod.content.block.entity.ParachestBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.component.DataComponents;
Expand Down Expand Up @@ -58,14 +58,14 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

public class ParaChestBlock extends GCBlock implements EntityBlock {
public class ParachestBlock extends GCBlock implements EntityBlock {
public static final String COLOR_TAG = "color";
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final EnumProperty<DyeColor> COLOR = EnumProperty.create("color", DyeColor.class);

protected static final VoxelShape AABB = Block.box(1.0, 0.0, 1.0, 15.0, 14.0, 15.0);

public ParaChestBlock(Properties properties) {
public ParachestBlock(Properties properties) {
super(properties);
registerDefaultState(getStateDefinition().any().setValue(FACING, Direction.NORTH)
.setValue(COLOR, DyeColor.WHITE));
Expand Down Expand Up @@ -131,14 +131,14 @@ protected InteractionResult useWithoutItem(BlockState state, Level level, BlockP

@Override
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new ParaChestBlockEntity(blockPos, blockState);
return new ParachestBlockEntity(blockPos, blockState);
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
return level.isClientSide ? null : type == GCBlockEntityTypes.PARACHEST ? (level1, blockPos, blockState, blockEntity) -> {
((ParaChestBlockEntity) blockEntity).tick();
((ParachestBlockEntity) blockEntity).tick();
} : null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

import dev.galacticraft.mod.content.GCBlocks;
import dev.galacticraft.mod.content.GCFluids;
import dev.galacticraft.mod.content.block.entity.ParaChestBlockEntity;
import dev.galacticraft.mod.content.block.special.ParaChestBlock;
import dev.galacticraft.mod.content.block.entity.ParachestBlockEntity;
import dev.galacticraft.mod.content.block.special.ParachestBlock;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -55,20 +55,25 @@ public class ParachestEntity extends Entity {
public NonNullList<ItemStack> cargo;
public long fuelLevel;
private boolean placedChest;
public DyeColor color = DyeColor.WHITE;
private DyeColor color = DyeColor.WHITE;

public ParachestEntity(EntityType<?> entityType, Level level, NonNullList<ItemStack> cargo, long fuelLevel) {
public ParachestEntity(EntityType<?> entityType, Level level, NonNullList<ItemStack> cargo, DyeColor color, long fuelLevel) {
this(entityType, level);
this.cargo = NonNullList.withSize(cargo.size(), ItemStack.EMPTY);
Collections.copy(this.cargo, cargo);
this.placedChest = false;
this.fuelLevel = fuelLevel;
this.color = color;
}

public ParachestEntity(EntityType<?> entityType, Level level) {
super(entityType, level);
}

public DyeColor getColor() {
return DyeColor.byId(this.entityData.get(COLOR));
}

@Override
protected void defineSynchedData(SynchedEntityData.Builder compositeStateBuilder) {
compositeStateBuilder.define(COLOR, (byte) DyeColor.WHITE.getId());
Expand Down Expand Up @@ -167,11 +172,11 @@ private boolean tryPlaceAtPos(BlockPos pos) {
}

private boolean placeChest(BlockPos pos) {
if (this.level().setBlock(pos, GCBlocks.PARACHEST.defaultBlockState().setValue(ParaChestBlock.COLOR, DyeColor.byId(this.entityData.get(COLOR))), Block.UPDATE_ALL)) {
if (this.level().setBlock(pos, GCBlocks.PARACHEST.defaultBlockState().setValue(ParachestBlock.COLOR, this.getColor()), Block.UPDATE_ALL)) {
if (this.cargo != null) {
final BlockEntity te = this.level().getBlockEntity(pos);

if (te instanceof ParaChestBlockEntity chest) {
if (te instanceof ParachestBlockEntity chest) {
chest.setItems(NonNullList.withSize(this.cargo.size() + 1, ItemStack.EMPTY));

Collections.copy(chest.getItems(), this.cargo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public ParachuteItem(DyeColor color, Properties properties) {
}

public DyeColor getColor() {
return color;
return this.color;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,23 @@ public OverworldCelestialTeleporterType(Codec<Config> codec) {
@Override
public void onEnterAtmosphere(ServerLevel level, ServerPlayer player, CelestialBody<?, ?> body, CelestialBody<?, ?> fromBody, Config config) {
if (body.config() instanceof PlanetConfig planetConfig) {
var chestSpawn = planetConfig.celestialHandler().getParaChestSpawnLocation(player.serverLevel(), player, player.getRandom());
var chestSpawn = planetConfig.celestialHandler().getParachestSpawnLocation(player.serverLevel(), player, player.getRandom());
if (chestSpawn != null) {
var gcPlayer = GCServerPlayer.get(player);
var rocketInv = gcPlayer.getRocketStacks();
ParachestEntity chest = new ParachestEntity(GCEntityTypes.PARACHEST, level, rocketInv, gcPlayer.getFuel());
rocketInv.clear();

chest.setPos(chestSpawn);

Container gearInv = player.galacticraft$getGearInv();
DyeColor color = DyeColor.WHITE;
for (int slot = 0; slot < gearInv.getContainerSize(); slot++) {
if (player.galacticraft$getGearInv().getItem(slot).getItem() instanceof ParachuteItem parachute) {
if (gearInv.getItem(slot).getItem() instanceof ParachuteItem parachute) {
color = parachute.getColor();
break;
}
}
chest.color = color;

var gcPlayer = GCServerPlayer.get(player);
var rocketInv = gcPlayer.getRocketStacks();
ParachestEntity chest = new ParachestEntity(GCEntityTypes.PARACHEST, level, rocketInv, color, gcPlayer.getFuel());
rocketInv.clear();

chest.setPos(chestSpawn);

level.addFreshEntity(chest);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import dev.galacticraft.mod.content.GCBlockRegistry.DecorationSet;
import dev.galacticraft.mod.content.GCBlocks;
import dev.galacticraft.mod.content.block.special.ParaChestBlock;
import dev.galacticraft.mod.content.block.special.ParachestBlock;
import dev.galacticraft.mod.content.block.special.launchpad.AbstractLaunchPad;
import dev.galacticraft.mod.content.item.GCItems;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
Expand Down Expand Up @@ -286,7 +286,7 @@ public void generate() {

this.add(GCBlocks.AIR_LOCK_SEAL, noDrop());

this.add(GCBlocks.PARACHEST, createParaChestDrop(GCBlocks.PARACHEST));
this.add(GCBlocks.PARACHEST, createParachestDrop(GCBlocks.PARACHEST));
}

private LootTable.Builder createLaunchPadTable(Block block) {
Expand Down Expand Up @@ -328,13 +328,13 @@ public LootTable.Builder createCrystalClusterDrop(Block block, Item item) {
);
}

private LootTable.Builder createParaChestDrop(Block block) {
private LootTable.Builder createParachestDrop(Block block) {
LootPool.Builder pool = LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F));
for (DyeColor color : DyeColor.values()) {
pool.add(LootItem.lootTableItem(block)
.apply(SetComponentsFunction.setComponent(DataComponents.BASE_COLOR, color))
.when(LootItemBlockStatePropertyCondition.hasBlockStateProperties(block)
.setProperties(StatePropertiesPredicate.Builder.properties().hasProperty(ParaChestBlock.COLOR, color)
.setProperties(StatePropertiesPredicate.Builder.properties().hasProperty(ParachestBlock.COLOR, color)
)));
}
return LootTable.lootTable().withPool(this.applyExplosionCondition(block, pool));
Expand Down
Loading

0 comments on commit f8f2a65

Please sign in to comment.