Skip to content

Commit

Permalink
Pattern Enhancements, Dimension load fix and Technical Debt Cleanup (#…
Browse files Browse the repository at this point in the history
…303)

Co-authored-by: Craig (Jeryn) <[email protected]>
  • Loading branch information
50ap5ud5 and Jeryn99 authored Aug 18, 2024
1 parent a61d0f8 commit 4035590
Show file tree
Hide file tree
Showing 85 changed files with 1,743 additions and 995 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.4+" apply false
id "dev.architectury.loom" version "1.5+" apply false
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package whocraft.tardis_refined.api.event;

import net.minecraft.resources.ResourceLocation;

/** Object to identify the source of Shell updates.*/
public class ShellChangeSource {

private ResourceLocation id;

public ShellChangeSource(ResourceLocation id) {
this.id = id;
}

public ResourceLocation getId() {
return this.id;
}

public void setId(ResourceLocation id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package whocraft.tardis_refined.api.event;

import net.minecraft.resources.ResourceLocation;
import whocraft.tardis_refined.common.util.MiscHelper;
import whocraft.tardis_refined.common.util.RegistryHelper;

public class ShellChangeSources {

public static final ResourceLocation ROOT_TO_TARDIS_ID = RegistryHelper.makeKey("root_to_tardis");
public static final ResourceLocation GENERIC_UPDATE_ID = RegistryHelper.makeKey("generic_update");
public static final ResourceLocation REGEN_EXISTING_TARDIS_ID = RegistryHelper.makeKey("regen_existing_tardis");

public static final ShellChangeSource ROOT_TO_TARDIS = new ShellChangeSource(ROOT_TO_TARDIS_ID);
public static final ShellChangeSource GENERIC_UPDATE = new ShellChangeSource(GENERIC_UPDATE_ID);
public static final ShellChangeSource REGEN_EXISTING_TARDIS = new ShellChangeSource(REGEN_EXISTING_TARDIS_ID);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,21 @@ public class TardisCommonEvents {
}
});

public static final Event<ShellChange> SHELL_CHANGE_EVENT = new Event<>(ShellChange.class, listeners -> (tardisLevelOperator, theme, isSetupTardis) -> {
public static final Event<LockDoor> DOOR_LOCKED_EVENT = new Event<>(LockDoor.class, listeners -> (tardisLevelOperator) -> {
for(LockDoor listener : listeners) {
listener.onDoorLocked(tardisLevelOperator);
}
});

public static final Event<UnlockDoor> DOOR_UNLOCKED_EVENT = new Event<>(UnlockDoor.class, listeners -> (tardisLevelOperator) -> {
for(UnlockDoor listener : listeners) {
listener.onDoorUnlocked(tardisLevelOperator);
}
});

public static final Event<ShellChange> SHELL_CHANGE_EVENT = new Event<>(ShellChange.class, listeners -> (tardisLevelOperator, theme, shellChangeSource) -> {
for (ShellChange listener : listeners) {
listener.onShellChange(tardisLevelOperator, theme, isSetupTardis);
listener.onShellChange(tardisLevelOperator, theme, shellChangeSource);
}
});

Expand Down Expand Up @@ -136,9 +148,35 @@ public interface OpenDoor {
void onDoorOpen(TardisLevelOperator tardisLevelOperator);
}

/**
* An event that is triggered when the TARDIS Door is locked.
*/
@FunctionalInterface
public interface LockDoor {
/**
* Called when the TARDIS door is locked.
*
* @param tardisLevelOperator The operator of the TARDIS level.
*/
void onDoorLocked(TardisLevelOperator tardisLevelOperator);
}

/**
* An event that is triggered when the TARDIS Door is unlocked.
*/
@FunctionalInterface
public interface UnlockDoor {
/**
* Called when the TARDIS door is unlocked.
*
* @param tardisLevelOperator The operator of the TARDIS level.
*/
void onDoorUnlocked(TardisLevelOperator tardisLevelOperator);
}


/**
* An event that is triggered when the TARDIS desktp is changed.
* An event that is triggered when the TARDIS desktop is changed.
* Note: Only fired once all players have left the dimension
*/
@FunctionalInterface
Expand Down Expand Up @@ -177,9 +215,9 @@ public interface ShellChange {
*
* @param tardisLevelOperator The operator of the TARDIS level.
* @param theme The theme the TARDIS changed to.
* @param isSetupTardis if the Shell Change event was caused by a Tardis being setup from a Root Shell to a fully functioning version
* @param shellChangeSource - Finds the source of the Shell Update. E.g. If the Shell Change event was caused by a Tardis being setup from a Root Shell to a fully functioning version
*/
void onShellChange(TardisLevelOperator tardisLevelOperator, ResourceLocation theme, boolean isSetupTardis);
void onShellChange(TardisLevelOperator tardisLevelOperator, ResourceLocation theme, ShellChangeSource shellChangeSource);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import whocraft.tardis_refined.client.model.blockentity.door.interior.ShellDoorModel;
import whocraft.tardis_refined.client.model.blockentity.shell.ShellModelCollection;
import whocraft.tardis_refined.common.block.door.GlobalDoorBlock;
import whocraft.tardis_refined.common.block.door.InternalDoorBlock;
import whocraft.tardis_refined.common.blockentity.door.GlobalDoorBlockEntity;
import whocraft.tardis_refined.compat.ModCompatChecker;
import whocraft.tardis_refined.compat.portals.ImmersivePortalsClient;
Expand Down Expand Up @@ -39,10 +40,10 @@ public void render(GlobalDoorBlockEntity blockEntity, float partialTick, PoseSta
poseStack.translate(0.5F, 1.5F, 0.5F);
poseStack.mulPose(Axis.ZP.rotationDegrees(180F));
BlockState blockstate = blockEntity.getBlockState();
float rotation = blockstate.getValue(GlobalDoorBlock.FACING).toYRot();
float rotation = blockstate.getValue(InternalDoorBlock.FACING).toYRot();
poseStack.mulPose(Axis.YP.rotationDegrees(rotation));
ResourceLocation theme = blockEntity.theme();
boolean isOpen = blockstate.getValue(GlobalDoorBlock.OPEN);
boolean isOpen = blockstate.getValue(InternalDoorBlock.OPEN);

// Render slightly off the wall to prevent z-fighting.
poseStack.translate(0, 0, -0.01);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private static boolean teleportToInterior(TardisLevelOperator tardisLevelOperato
if (tpLevel instanceof ServerLevel finalTpLevel) {
if (tardisLevelOperator.getInternalDoor() != null) {
BlockPos pos = tardisLevelOperator.getInternalDoor().getDoorPosition();
pos = pos.relative(tardisLevelOperator.getInternalDoor().getEntryRotation(), 1);
pos = pos.relative(tardisLevelOperator.getInternalDoor().getTeleportRotation(), 1);
TRTeleporter.simpleTeleport(entity, finalTpLevel, pos.getX(), pos.getY(), pos.getZ(), entity.getYHeadRot(), entity.getXRot());
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,7 @@ public void onPlace(BlockState blockState, Level level, BlockPos blockPos, Block

if(level instanceof ServerLevel serverLevel && level.dimensionTypeId() == TRDimensionTypes.TARDIS){
TardisLevelOperator.get(serverLevel).ifPresent(TardisHelper::playCloisterBell);
level.removeBlock(blockPos, false);
ItemEntity item = new ItemEntity(EntityType.ITEM, level);
item.setItem(new ItemStack(TRBlockRegistry.ROOT_PLANT_BLOCK.get()));
item.setPos(blockPos.getX(), blockPos.getY(), blockPos.getZ());
level.addFreshEntity(item);
serverLevel.destroyBlock(blockPos, true); //Use Level#destroyBlock with boolean flag to TRUE so that it both destroys the block and drops its resources based off its loot table, which is the source of truth.
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,50 +170,44 @@ public void animateTick(BlockState blockState, Level level, BlockPos blockPos, R
@Override
public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {


if (level instanceof ServerLevel serverLevel && level.dimensionTypeId() == TRDimensionTypes.TARDIS) {

TardisLevelOperator.get(serverLevel).ifPresent(operator -> {
TardisPilotingManager pilotingManager = operator.getPilotingManager();

if (serverLevel.getBlockEntity(blockPos) instanceof GlobalConsoleBlockEntity consoleBlockEntity) {
if (pilotingManager.getCurrentConsole() != null) {
if (pilotingManager.getCurrentConsole() != consoleBlockEntity) {

if (!pilotingManager.isInFlight()) {
pilotingManager.setCurrentConsole(consoleBlockEntity);

} else {
PlayerUtil.sendMessage(player, ModMessages.CONSOLE_NOT_IN_FLIGHT, true);
if (!player.level().isClientSide()) {
if (level instanceof ServerLevel serverLevel && level.dimensionTypeId() == TRDimensionTypes.TARDIS) {
TardisLevelOperator.get(serverLevel).ifPresent(operator -> {
TardisPilotingManager pilotingManager = operator.getPilotingManager();
if (serverLevel.getBlockEntity(blockPos) instanceof GlobalConsoleBlockEntity consoleBlockEntity) {
if (pilotingManager.getCurrentConsole() != null) {
if (pilotingManager.getCurrentConsole() != consoleBlockEntity) {
if (!pilotingManager.isInFlight()) {
pilotingManager.setCurrentConsole(consoleBlockEntity);
} else {
PlayerUtil.sendMessage(player, ModMessages.CONSOLE_NOT_IN_FLIGHT, true);
}
}

} else {
pilotingManager.setCurrentConsole(consoleBlockEntity);
consoleBlockEntity.getUpdatePacket();
}
} else {
pilotingManager.setCurrentConsole(consoleBlockEntity);
consoleBlockEntity.getUpdatePacket();
}
}

});

// Creative only: Quickly complete the cooldown.
if (player.isCreative() && player.getItemInHand(interactionHand).getItem() == Items.ICE) {
var operatorOptional = TardisLevelOperator.get(serverLevel);
if (operatorOptional.isPresent()) {
var operator = operatorOptional.get();
TardisPilotingManager pilotManager = operator.getPilotingManager();

if (pilotManager.isOnCooldown()) {
pilotManager.endCoolDown();
});

// Creative only: Quickly complete the cooldown.
if (player.isCreative() && player.getItemInHand(interactionHand).getItem() == Items.ICE) {
var operatorOptional = TardisLevelOperator.get(serverLevel);
if (operatorOptional.isPresent()) {
var operator = operatorOptional.get();
TardisPilotingManager pilotManager = operator.getPilotingManager();

return InteractionResult.CONSUME_PARTIAL;
if (pilotManager.isOnCooldown()) {
pilotManager.endCoolDown();
return InteractionResult.sidedSuccess(false); //Use InteractionResult.sidedSuccess(false) for non-client side. Stops hand swinging twice. We don't want to use InteractionResult.SUCCESS because the client calls SUCCESS, so the server side calling it too sends the hand swinging packet twice.
}
}
}

}
}
}

return super.use(blockState, level, blockPos, player, interactionHand, blockHitResult);
return InteractionResult.sidedSuccess(true); //Use InteractionResult.sidedSuccess(true) for client side. Stops hand swinging twice. We don't want to use InteractionResult.SUCCESS because the client calls SUCCESS, so the server side calling it too sends the hand swinging packet twice.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
player.swing(interactionHand, true);

level.setBlockAndUpdate(blockPos, blockState.setValue(SPACE, newSpace));
return super.use(blockState, level, blockPos, player, interactionHand, blockHitResult);
return InteractionResult.sidedSuccess(false); //Use InteractionResult.sidedSuccess(false) for non-client side. Stops hand swinging twice. We don't want to use InteractionResult.SUCCESS because the client calls SUCCESS, so the server side calling it too sends the hand swinging packet twice.
}
return super.use(blockState, level, blockPos, player, interactionHand, blockHitResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public void onPlace(BlockState blockState, Level level, BlockPos blockPos, Block
super.onPlace(blockState, level, blockPos, blockState2, bl);

if (level.getBlockState(blockPos.below()).getBlock() == TRBlockRegistry.ARTRON_PILLAR_PORT.get()) {
level.setBlock(blockPos, blockState.setValue(ACTIVE, true), 3);
level.playSound(null, blockPos, TRSoundRegistry.ARTRON_PILLAR.get(), SoundSource.BLOCKS, 100, 1 + (level.getRandom().nextFloat() * 0.25f));
level.setBlock(blockPos, blockState.setValue(ACTIVE, true), Block.UPDATE_ALL);
level.playSound(null, blockPos, TRSoundRegistry.ARTRON_PILLAR_ACTIVE.get(), SoundSource.BLOCKS, 100, 1 + (level.getRandom().nextFloat() * 0.25f));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
if (itemStack == ItemStack.EMPTY) {
astralManipulatorBlockEntity.clearDisplay();

return InteractionResult.CONSUME;
return InteractionResult.sidedSuccess(false);
} else {

if (itemStack.getItem() instanceof ScrewdriverItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,33 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP
return InteractionResult.PASS;
}

if (!player.level().isClientSide()) {

var offset = blockState.getValue(FACING).getNormal();
BlockPos consolePos = blockPos.offset(offset);
var offset = blockState.getValue(FACING).getNormal();
BlockPos consolePos = blockPos.offset(offset);

if (player.getMainHandItem().getItem() == TRItemRegistry.PATTERN_MANIPULATOR.get()) {
this.changePattern(level, blockPos, consolePos, player);
return InteractionResult.SUCCESS;
}
if (player.getMainHandItem().getItem() == TRItemRegistry.PATTERN_MANIPULATOR.get()) {
this.changePattern(level, blockPos, consolePos, player);
return InteractionResult.sidedSuccess(false); //Use InteractionResult.sidedSuccess(false) for non-client side. Stops hand swinging twice. We don't want to use InteractionResult.SUCCESS because the client calls SUCCESS, so the server side calling it too sends the hand swinging packet twice.
}

if (level instanceof ServerLevel serverLevel) {
TardisLevelOperator.get(serverLevel).ifPresent(operator -> {
if (!operator.getPilotingManager().isInFlight()) {
if (player.isShiftKeyDown()) { //If we are destroying the console block
this.removeGlobalConsoleBlock(consolePos, level);
if (level instanceof ServerLevel serverLevel) {
TardisLevelOperator.get(serverLevel).ifPresent(operator -> {
if (!operator.getPilotingManager().isInFlight()) {
if (player.isShiftKeyDown()) { //If we are destroying the console block
this.removeGlobalConsoleBlock(consolePos, level);
} else {
this.changeConsoleTheme(level, blockPos, consolePos);
}
} else {
this.changeConsoleTheme(level, blockPos, consolePos);
PlayerUtil.sendMessage(player, Component.translatable(ModMessages.CONSOLE_CONFIGURATION_NOT_IN_FLIGHT), true);
}
} else {
PlayerUtil.sendMessage(player, Component.translatable(ModMessages.CONSOLE_CONFIGURATION_NOT_IN_FLIGHT), true);
}
});
});
}
return InteractionResult.sidedSuccess(false); //Use InteractionResult.sidedSuccess(false) for non-client side. Stops hand swinging twice. We don't want to use InteractionResult.SUCCESS because the client calls SUCCESS, so the server side calling it too sends the hand swinging packet twice.
}

return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(true); //Use InteractionResult.sidedSuccess(true) for client side. Stops hand swinging twice. We don't want to use InteractionResult.SUCCESS because the client calls SUCCESS, so the server side calling it too sends the hand swinging packet twice.
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
Expand All @@ -25,12 +21,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import whocraft.tardis_refined.common.blockentity.device.CorridorTeleporterBlockEntity;
import whocraft.tardis_refined.common.blockentity.life.EyeBlockEntity;
import whocraft.tardis_refined.common.tardis.ExteriorShell;
import whocraft.tardis_refined.common.util.ClientHelper;
import whocraft.tardis_refined.common.util.TRTeleporter;
import whocraft.tardis_refined.registry.TRBlockEntityRegistry;
import whocraft.tardis_refined.registry.TRDimensionTypes;

public class CorridorTeleporterBlock extends Block implements EntityBlock {

Expand Down
Loading

0 comments on commit 4035590

Please sign in to comment.