Skip to content

Commit

Permalink
start fixing build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Octol1ttle committed Jul 24, 2024
1 parent 4c3e848 commit 7cc3b96
Show file tree
Hide file tree
Showing 59 changed files with 599 additions and 742 deletions.
57 changes: 10 additions & 47 deletions src/main/java/net/splatcraft/forge/Splatcraft.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package net.splatcraft.forge;

import net.minecraft.network.chat.Component;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
import net.minecraft.server.packs.repository.Pack;
import net.minecraft.server.packs.repository.PackSource;
import java.util.Objects;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.AddPackFindersEvent;
import net.minecraftforge.event.server.ServerStartedEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
Expand All @@ -18,22 +13,23 @@
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLPaths;
import net.minecraftforge.forgespi.language.IModInfo;
import net.minecraftforge.resource.PathResourcePack;
import net.splatcraft.forge.client.handlers.ClientSetupHandler;
import net.splatcraft.forge.client.handlers.SplatcraftKeyHandler;
import net.splatcraft.forge.data.SplatcraftTags;
import net.splatcraft.forge.handlers.ScoreboardHandler;
import net.splatcraft.forge.network.SplatcraftPacketHandler;
import net.splatcraft.forge.registries.*;
import net.splatcraft.forge.registries.SplatcraftBlocks;
import net.splatcraft.forge.registries.SplatcraftCommands;
import net.splatcraft.forge.registries.SplatcraftEntities;
import net.splatcraft.forge.registries.SplatcraftGameRules;
import net.splatcraft.forge.registries.SplatcraftItems;
import net.splatcraft.forge.registries.SplatcraftRegisties;
import net.splatcraft.forge.registries.SplatcraftStats;
import net.splatcraft.forge.registries.SplatcraftTileEntities;
import net.splatcraft.forge.worldgen.SplatcraftOreGen;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Objects;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(Splatcraft.MODID)
public class Splatcraft {
Expand All @@ -58,7 +54,6 @@ public Splatcraft() {

FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setupBuiltInPacks);

MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(FMLJavaModLoadingContext.get().getModEventBus());
Expand Down Expand Up @@ -100,36 +95,4 @@ public void onServerStarted(ServerStartedEvent event)
SplatcraftGameRules.booleanRules.replaceAll((k, v) -> event.getServer().getGameRules().getBoolean(SplatcraftGameRules.getRuleFromIndex(k)));
SplatcraftGameRules.intRules.replaceAll((k, v) -> event.getServer().getGameRules().getInt(SplatcraftGameRules.getRuleFromIndex(k)));
}

private static final ArrayList<ResourcePack> BUILTIN_PACKS = new ArrayList<>();
public void setupBuiltInPacks(AddPackFindersEvent event)
{
if(event.getPackType() == PackType.CLIENT_RESOURCES)
{
for(ResourcePack pack : BUILTIN_PACKS)
try {
Path path = ModList.get().getModFileById(MODID).getFile().findResource("resourcepacks/" + pack.folder);
PathResourcePack packPath = new PathResourcePack(ModList.get().getModFileById(MODID).getFile().getFileName() + ":" + path, path);
PackMetadataSection section = packPath.getMetadataSection(PackMetadataSection.SERIALIZER);

if(section != null)
{
event.addRepositorySource((packConsumer, packConstructor) -> packConsumer.accept(packConstructor.create(
"builtin/" + Splatcraft.MODID, pack.displayName, false,
() -> packPath, section, Pack.Position.BOTTOM, PackSource.BUILT_IN, false
)));
}

} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

record ResourcePack(String folder, Component displayName){}

public void addBuiltinPack(String folder, Component displayName)
{
BUILTIN_PACKS.add(new ResourcePack(folder, displayName));
}
}
}
118 changes: 45 additions & 73 deletions src/main/java/net/splatcraft/forge/blocks/BarrierBarBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,21 @@
import net.minecraft.world.level.block.state.properties.*;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;

@SuppressWarnings("deprecation")
public class BarrierBarBlock extends Block implements SimpleWaterloggedBlock
{
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final EnumProperty<Half> HALF = BlockStateProperties.HALF;
public static final EnumProperty<StairsShape> SHAPE = BlockStateProperties.STAIRS_SHAPE;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;

protected static final AABB STRAIGHT_AABB = new AABB(0, 13 / 16f, 13 / 16f, 1, 1, 1);
protected static final AABB EDGE_AABB = new AABB(0, 13 / 16f, 13 / 16f, 3 / 16f, 1, 1);
protected static final AABB ROTATED_STRAIGHT_AABB = modifyShapeForDirection(Direction.EAST, Shapes.create(STRAIGHT_AABB)).bounds();
protected static final AABB TOP_AABB = new AABB(0, 13 / 16f, 0, 1, 1, 1);

protected static final VoxelShape NU_STRAIGHT = Block.box(0, 13, 0, 16, 16, 3);
protected static final VoxelShape SU_STRAIGHT = modifyShapeForDirection(Direction.SOUTH, NU_STRAIGHT);
protected static final VoxelShape WU_STRAIGHT = modifyShapeForDirection(Direction.WEST, NU_STRAIGHT);
Expand All @@ -56,24 +51,20 @@ public class BarrierBarBlock extends Block implements SimpleWaterloggedBlock

public BarrierBarBlock()
{
super(BlockBehaviour.Properties.of(Material.METAL, MaterialColor.NONE).strength(3.0f).requiresCorrectToolForDrops());
super(BlockBehaviour.Properties.of().strength(3.0f).requiresCorrectToolForDrops());
this.registerDefaultState(this.getStateDefinition().any().setValue(FACING, Direction.NORTH).setValue(HALF, Half.BOTTOM).setValue(SHAPE, StairsShape.STRAIGHT).setValue(WATERLOGGED, false));
}

protected static VoxelShape modifyShapeForDirection(Direction facing, VoxelShape shape)
{
AABB bb = shape.bounds();

switch (facing)
{
case EAST:
return Shapes.create(new AABB(1 - bb.maxZ, bb.minY, bb.minX, 1 - bb.minZ, bb.maxY, bb.maxX));
case SOUTH:
return Shapes.create(new AABB(1 - bb.maxX, bb.minY, 1 - bb.maxZ, 1 - bb.minX, bb.maxY, 1 - bb.minZ));
case WEST:
return Shapes.create(new AABB(bb.minZ, bb.minY, 1 - bb.maxX, bb.maxZ, bb.maxY, 1 - bb.minX));
}
return shape;
return switch (facing) {
case EAST -> Shapes.create(new AABB(1 - bb.maxZ, bb.minY, bb.minX, 1 - bb.minZ, bb.maxY, bb.maxX));
case SOUTH -> Shapes.create(new AABB(1 - bb.maxX, bb.minY, 1 - bb.maxZ, 1 - bb.minX, bb.maxY, 1 - bb.minZ));
case WEST -> Shapes.create(new AABB(bb.minZ, bb.minY, 1 - bb.maxX, bb.maxZ, bb.maxY, 1 - bb.minX));
default -> shape;
};
}

public static VoxelShape mirrorShapeY(VoxelShape shape)
Expand All @@ -83,13 +74,6 @@ public static VoxelShape mirrorShapeY(VoxelShape shape)
return Shapes.create(new AABB(bb.minX, 1 - bb.minY, bb.minZ, bb.maxX, 1 - bb.maxY, bb.maxZ));
}

public static VoxelShape mirrorShapeX(VoxelShape shape)
{
AABB bb = shape.bounds();

return Shapes.create(new AABB(1 - bb.minX, bb.minY, bb.minZ, 1 - bb.maxX, bb.maxY, bb.maxZ));
}

/**
* Returns a stair shape property based on the surrounding stairs from the given blockstate and position
*/
Expand Down Expand Up @@ -141,32 +125,25 @@ public static boolean isBar(BlockState state)
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context)
public @NotNull VoxelShape getShape(BlockState state, @NotNull BlockGetter levelIn, @NotNull BlockPos pos, @NotNull CollisionContext context)
{
VoxelShape[] shapeArray = state.getValue(HALF).equals(Half.TOP) ? TOP_SHAPES : BOTTOM_SHAPES;
int dirIndex = state.getValue(FACING).ordinal() - 2;
int rotatedDirIndex = state.getValue(FACING).getClockWise().ordinal() - 2;
int rotatedCCWDirIndex = state.getValue(FACING).getCounterClockWise().ordinal() - 2;

switch (state.getValue(SHAPE))
{
case STRAIGHT:
return shapeArray[dirIndex];
case OUTER_LEFT:
return shapeArray[dirIndex + 4];
case OUTER_RIGHT:
return shapeArray[rotatedDirIndex + 4];
case INNER_LEFT:
return Shapes.or(shapeArray[dirIndex], shapeArray[rotatedCCWDirIndex]);
case INNER_RIGHT:
return Shapes.or(shapeArray[dirIndex], shapeArray[rotatedDirIndex]);
}
return switch (state.getValue(SHAPE)) {
case STRAIGHT -> shapeArray[dirIndex];
case OUTER_LEFT -> shapeArray[dirIndex + 4];
case OUTER_RIGHT -> shapeArray[rotatedDirIndex + 4];
case INNER_LEFT -> Shapes.or(shapeArray[dirIndex], shapeArray[rotatedCCWDirIndex]);
case INNER_RIGHT -> Shapes.or(shapeArray[dirIndex], shapeArray[rotatedDirIndex]);
};

return Block.box(1, 1, 1, 15, 15, 15);
}

@Override
public boolean useShapeForLightOcclusion(BlockState state)
public boolean useShapeForLightOcclusion(@NotNull BlockState state)
{
return true;
}
Expand All @@ -182,7 +159,7 @@ public BlockState getStateForPlacement(BlockPlaceContext context)
}

@Override
public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor levelIn, BlockPos currentPos, BlockPos facingPos)
public @NotNull BlockState updateShape(BlockState stateIn, @NotNull Direction facing, @NotNull BlockState facingState, @NotNull LevelAccessor levelIn, @NotNull BlockPos currentPos, @NotNull BlockPos facingPos)
{
if (stateIn.getValue(WATERLOGGED))
{
Expand All @@ -193,13 +170,13 @@ public BlockState updateShape(BlockState stateIn, Direction facing, BlockState f
}

@Override
public BlockState rotate(BlockState state, Rotation rot)
public @NotNull BlockState rotate(BlockState state, Rotation rot)
{
return state.setValue(FACING, rot.rotate(state.getValue(FACING)));
}

@Override
public BlockState mirror(BlockState state, Mirror mirrorIn)
public @NotNull BlockState mirror(BlockState state, Mirror mirrorIn)
{
Direction direction = state.getValue(FACING);
StairsShape stairsshape = state.getValue(SHAPE);
Expand All @@ -208,37 +185,32 @@ public BlockState mirror(BlockState state, Mirror mirrorIn)
case LEFT_RIGHT:
if (direction.getAxis() == Direction.Axis.Z)
{
switch (stairsshape)
{
case INNER_LEFT:
return state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.INNER_RIGHT);
case INNER_RIGHT:
return state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.INNER_LEFT);
case OUTER_LEFT:
return state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.OUTER_RIGHT);
case OUTER_RIGHT:
return state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.OUTER_LEFT);
default:
return state.rotate(Rotation.CLOCKWISE_180);
}
return switch (stairsshape) {
case INNER_LEFT ->
state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.INNER_RIGHT);
case INNER_RIGHT ->
state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.INNER_LEFT);
case OUTER_LEFT ->
state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.OUTER_RIGHT);
case OUTER_RIGHT ->
state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.OUTER_LEFT);
default -> state.rotate(Rotation.CLOCKWISE_180);
};
}
break;
case FRONT_BACK:
if (direction.getAxis() == Direction.Axis.X)
{
switch (stairsshape)
{
case INNER_LEFT:
return state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.INNER_LEFT);
case INNER_RIGHT:
return state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.INNER_RIGHT);
case OUTER_LEFT:
return state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.OUTER_RIGHT);
case OUTER_RIGHT:
return state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.OUTER_LEFT);
case STRAIGHT:
return state.rotate(Rotation.CLOCKWISE_180);
}
return switch (stairsshape) {
case INNER_LEFT -> state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.INNER_LEFT);
case INNER_RIGHT ->
state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.INNER_RIGHT);
case OUTER_LEFT ->
state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.OUTER_RIGHT);
case OUTER_RIGHT ->
state.rotate(Rotation.CLOCKWISE_180).setValue(SHAPE, StairsShape.OUTER_LEFT);
case STRAIGHT -> state.rotate(Rotation.CLOCKWISE_180);
};
}
}

Expand All @@ -252,16 +224,16 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
}

@Override
public FluidState getFluidState(BlockState state)
public @NotNull FluidState getFluidState(BlockState state)
{
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
}

@Override
public boolean isPathfindable(BlockState state, BlockGetter levelIn, BlockPos pos, PathComputationType type)
public boolean isPathfindable(@NotNull BlockState state, @NotNull BlockGetter levelIn, @NotNull BlockPos pos, @NotNull PathComputationType type)
{
return false;
}


}
}
20 changes: 12 additions & 8 deletions src/main/java/net/splatcraft/forge/blocks/CanvasBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.phys.HitResult;
import net.splatcraft.forge.registries.SplatcraftBlocks;
import net.splatcraft.forge.registries.SplatcraftTileEntities;
Expand All @@ -26,28 +26,32 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@SuppressWarnings("deprecation")
public class CanvasBlock extends Block implements IColoredBlock, EntityBlock
{

public static final BooleanProperty INKED = BooleanProperty.create("inked");

public CanvasBlock(String name)
public CanvasBlock()
{
super(Properties.of(Material.WOOL).strength(0.8f).sound(SoundType.WOOL));
super(Properties.of().mapColor(MapColor.WOOL).ignitedByLava().strength(0.8f).sound(SoundType.WOOL));
SplatcraftBlocks.inkColoredBlocks.add(this);
registerDefaultState(defaultBlockState().setValue(INKED, false));
}

@Nullable
@Override
public BlockState getStateForPlacement(BlockPlaceContext context)
public BlockState getStateForPlacement(@NotNull BlockPlaceContext context)
{
return super.getStateForPlacement(context).setValue(INKED, ColorUtils.getInkColor(context.getItemInHand()) != -1);
BlockState state = super.getStateForPlacement(context);
if (state == null) {
return null;
}
return state.setValue(INKED, ColorUtils.getInkColor(context.getItemInHand()) != -1);
}

@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state)
public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state)
{
InkColorTileEntity te = SplatcraftTileEntities.colorTileEntity.get().create(pos, state);
if (te != null)
Expand Down Expand Up @@ -152,4 +156,4 @@ public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGett
return ColorUtils.setColorLocked(ColorUtils.setInkColor(stack, getColor((Level) level, pos)), true);
return stack;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public VoxelShape getCollisionShape(BlockState state, BlockGetter levelIn, Block

public boolean canAllowThrough(BlockPos pos, Entity entity)
{
return blocksColor != ColorUtils.colorEquals(entity, entity.level.getBlockEntity(pos));
return blocksColor != ColorUtils.colorEquals(entity, entity.level().getBlockEntity(pos));
}

@Override
Expand Down Expand Up @@ -125,4 +125,4 @@ public boolean remoteColorChange(Level level, BlockPos pos, int newColor)
public boolean remoteInkClear(Level level, BlockPos pos) {
return false;
}
}
}
Loading

0 comments on commit 7cc3b96

Please sign in to comment.