Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "maven.modrinth:valkyrien-skies:1.20.1-fabric-2.3.0-beta.5"
modImplementation "maven.modrinth:eureka:1.20.1-fabric-1.5.1-beta.3"
modImplementation "maven.modrinth:valkyrien-sails:1.20.1-0.1.6-fabric"

modImplementation "maven.modrinth:vlib:1.20.1-0.0.7-alpha+fabric"

Expand Down
68 changes: 55 additions & 13 deletions src/main/java/ace/actually/pirates/Pirates.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.resource.ResourceType;
import net.minecraft.server.MinecraftServer;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
Expand All @@ -50,7 +48,6 @@
import org.slf4j.LoggerFactory;

import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class Pirates implements ModInitializer {
Expand All @@ -70,31 +67,72 @@ public class Pirates implements ModInitializer {
.build();

public static float baseShotPower;
public static float cannonRange;
public static int pursuitDistance;
public static boolean shouldEnableFlyingPirates;
public static Supplier<ItemStack> recruitCost;
public static CompatTracker loadedCompats = new CompatTracker();

@Override
public void onInitialize() {

Optional<ModContainer> container = FabricLoader.getInstance().getModContainer(Pirates.MOD_ID);

if (container.isPresent()) {
if(ResourceManagerHelper.registerBuiltinResourcePack(
new Identifier("flying_ships"),
container.get(),
ResourcePackActivationType.NORMAL
)) {
LOGGER.info("Registered flying ships data pack");
if (FabricLoader.getInstance().isModLoaded("vs_sails")) {
loadedCompats.sails = true;

if (container.isPresent()) {
if(ResourceManagerHelper.registerBuiltinResourcePack(
new Identifier("sails_ships"),
container.get(),
ResourcePackActivationType.DEFAULT_ENABLED
)) {
LOGGER.info("Registered vs_sails ships data pack");
} else {
LOGGER.warn("vs_sails ships data pack didn't work");
}
} else {
LOGGER.warn("didn't work");
LOGGER.warn("Failed to register vs_sails ships data pack");
}
}
if (FabricLoader.getInstance().isModLoaded("vs_eureka")) {
loadedCompats.eureka = true;

if (container.isPresent()) {
ResourcePackActivationType eurekaActivation =
loadedCompats.sails ? ResourcePackActivationType.NORMAL : ResourcePackActivationType.DEFAULT_ENABLED;

if(ResourceManagerHelper.registerBuiltinResourcePack(
new Identifier("eureka_ships"),
container.get(),
eurekaActivation
)) {
LOGGER.info("Registered vs_eureka ships data pack");
} else {
LOGGER.warn("vs_eureka ships data pack didn't work");
}
} else {
LOGGER.warn("Failed to register vs_eureka ships data pack");
}

if (container.isPresent()) {
if(ResourceManagerHelper.registerBuiltinResourcePack(
new Identifier("flying_ships"),
container.get(),
ResourcePackActivationType.NORMAL
)) {
LOGGER.info("Registered flying ships data pack");
} else {
LOGGER.warn("didn't work");
}
} else {
LOGGER.warn("Failed to register flying ships data pack");
}
} else {
LOGGER.warn("Failed to register flying ships data pack");
}

ConfigUtils.checkConfigs();
baseShotPower = Float.parseFloat(ConfigUtils.config.getOrDefault("base-shot-power","2.2"));
cannonRange = Float.parseFloat(ConfigUtils.config.getOrDefault("cannon-range","1.7"));
pursuitDistance = Integer.parseInt(ConfigUtils.config.getOrDefault("pursuit-distance","10000"));
shouldEnableFlyingPirates = ConfigUtils.config.getOrDefault("should-enable-flying-pirates","false").equals("true");

Expand Down Expand Up @@ -239,5 +277,9 @@ public static <T extends Entity> EntityType<T> registerEntity(String name, Spawn

}

public static class CompatTracker {
public boolean eureka = false;
public boolean sails = false;

}
}
19 changes: 3 additions & 16 deletions src/main/java/ace/actually/pirates/blocks/CannonPrimingBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.world.*;
import org.jetbrains.annotations.Nullable;

@SuppressWarnings("deprecation")
public class CannonPrimingBlock extends BlockWithEntity {
public CannonPrimingBlock(Settings settings) {
super(settings);
Expand Down Expand Up @@ -78,20 +79,6 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, Block
return checkType(type, Pirates.CANNON_PRIMING_BLOCK_ENTITY, (world1, pos, state1, be) -> be.tick(world1, pos, state1, be));
}

// @Override
// public boolean emitsRedstonePower(BlockState state) {
// return state.get(RedstoneLampBlock.LIT);
// }
//
// @Override
// public int getWeakRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction direction) {
// if(state.get(RedstoneLampBlock.LIT))
// {
// return 15;
// }
// return 0;
// }

@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {

Expand All @@ -104,11 +91,11 @@ public BlockState getStateForNeighborUpdate(BlockState state, Direction directio
}

public BlockState rotate(BlockState state, BlockRotation rotation) {
return (BlockState)state.with(Properties.FACING, rotation.rotate((Direction)state.get(Properties.FACING)));
return state.with(Properties.FACING, rotation.rotate(state.get(Properties.FACING)));
}

public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation((Direction)state.get(Properties.FACING)));
return state.rotate(mirror.getRotation(state.get(Properties.FACING)));
}

public static void disarm(World world, BlockPos pos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected ProjectileEntity createProjectile(World world, Position position, Item
return super.getBehaviorForItem(stack);
}

@SuppressWarnings("deprecation")
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {

Expand Down
59 changes: 41 additions & 18 deletions src/main/java/ace/actually/pirates/blocks/MotionInvokingBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ace.actually.pirates.Pirates;
import ace.actually.pirates.blocks.entity.MotionInvokingBlockEntity;
import ace.actually.pirates.util.EurekaCompat;
import ace.actually.pirates.util.SailsCompat;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
Expand All @@ -16,7 +17,8 @@
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
Expand All @@ -30,6 +32,7 @@

public class MotionInvokingBlock extends BlockWithEntity {
public static final BooleanProperty ARMED = BooleanProperty.of("armed");
public static final IntProperty COMPAT = IntProperty.of("compat", 0, 2);

public MotionInvokingBlock(Settings settings) {
super(settings);
Expand All @@ -39,25 +42,44 @@ public MotionInvokingBlock(Settings settings) {
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(ARMED);
builder.add(COMPAT);
}

@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return super.getPlacementState(ctx).with(ARMED,true);
int compatVal = 0;
if (Pirates.loadedCompats.sails && SailsCompat.checkHelm(ctx.getWorld(), ctx.getBlockPos())) {
compatVal = 1;
}
if (Pirates.loadedCompats.eureka && EurekaCompat.checkHelm(ctx.getWorld(), ctx.getBlockPos())) {
compatVal = 2;
}
return super.getPlacementState(ctx).with(ARMED,true).with(COMPAT, compatVal);
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if(world instanceof ServerWorld serverWorld && player.getStackInHand(hand).isOf(Items.DEBUG_STICK))
{
MotionInvokingBlockEntity be = (MotionInvokingBlockEntity) serverWorld.getBlockEntity(pos);
be.setCompat("None");
}
// if(world instanceof ServerWorld serverWorld && player.getStackInHand(hand).isOf(Items.DEBUG_STICK)) {
// MotionInvokingBlockEntity be = (MotionInvokingBlockEntity) serverWorld.getBlockEntity(pos);
// be.setCompat("None");
// }
return super.onUse(state, world, pos, player, hand, hit);
}

@Nullable
@Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
state.with(COMPAT, 0);
if (Pirates.loadedCompats.sails && SailsCompat.checkHelm(world, pos)) {
state.with(COMPAT, 1);
}
if (Pirates.loadedCompats.eureka && EurekaCompat.checkHelm(world, pos)) {
state.with(COMPAT, 2);
}
world.setBlockState(pos, state, 10);
}

@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new MotionInvokingBlockEntity(pos, state);
Expand All @@ -78,7 +100,10 @@ public void onStacksDropped(BlockState state, ServerWorld world, BlockPos pos, I

@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
stopMotion(world,pos);
// if (!newState.get(ARMED)) { //fixme nullptr exception?
// stopMotion(world,pos); //fixme figure out how to activate this only when newState is not a MotionInvokingBlock
// } //potentially could just move the stopMotion call into disarm()
//
super.onStateReplaced(state, world, pos, newState, moved);

}
Expand All @@ -93,21 +118,19 @@ public static void disarm(World world, BlockPos pos) {

world.setBlockState(pos, Pirates.MOTION_INVOKING_BLOCK.getDefaultState().with(ARMED,false));
world.playSound(null, pos, SoundEvents.BLOCK_BEACON_DEACTIVATE, SoundCategory.BLOCKS, 1, 0.95f);

stopMotion(world,pos); //fixme possibly an issue
}

private static void stopMotion(World world, BlockPos pos)
{
if(!world.isClient)
{
private static void stopMotion(World world, BlockPos pos) {
if(!world.isClient) {
DimensionIdProvider provider = (DimensionIdProvider) world;
ChunkPos chunkPos = world.getChunk(pos).getPos();
LoadedServerShip ship = (LoadedServerShip) ValkyrienSkiesMod.getVsCore().getHooks().getCurrentShipServerWorld().getLoadedShips().getByChunkPos(chunkPos.x, chunkPos.z, provider.getDimensionId());
if(ship!=null)
{
if(ship!=null) {
MotionInvokingBlockEntity be = (MotionInvokingBlockEntity) world.getBlockEntity(pos);
if(be!=null && be.getCompat().equals("Eureka"))
{
if(world.getBlockState(pos).get(COMPAT).equals(1)) {
SailsCompat.stopMotion(ship);
} else if (world.getBlockState(pos).get(COMPAT).equals(2)) {
EurekaCompat.stopMotion(ship);
}
}
Expand Down
Loading