Skip to content

Commit

Permalink
- fixed bug where upgrade screen wouldn't update with new information
Browse files Browse the repository at this point in the history
- fixed issue where ars room one has no ars eggs, blocking progression
  • Loading branch information
Jeryn99 committed Dec 22, 2023
1 parent 0e8fe8e commit a7c6db5
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
Expand All @@ -28,7 +29,6 @@ public class UpgradeTab {
private final UpgradeTabType type;
private final int index;
public final UpgradeHandler upgradeHandler;
private final ItemStack icon;
private final Component title;
private final List<UpgradeWidget> entries = new ArrayList<>();
private final List<Connection> connections = new ArrayList<>();
Expand All @@ -47,14 +47,15 @@ public UpgradeTab(Minecraft minecraft, UpgradesScreen UpgradesScreen, UpgradeTab
this.type = tabType;
this.index = i;
this.upgradeHandler = powerHolder;
this.icon = new ItemStack(Items.COOKED_PORKCHOP);
this.title = Component.literal("");
this.populate(powerHolder);
}

public void populate(UpgradeHandler upgradeHandlerClient) {
this.entries.clear();
this.connections.clear();
CompoundTag newData = upgradeHandlerClient.saveData(new CompoundTag());
this.upgradeHandler.loadData(newData);
List<UpgradeWidget> root = new LinkedList<>();

// Create entry for each ability
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package whocraft.tardis_refined.common.blockentity.door;

import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.player.Player;
Expand All @@ -11,6 +12,10 @@
import net.minecraft.world.level.block.state.BlockState;
import whocraft.tardis_refined.common.block.door.BulkHeadDoorBlock;
import whocraft.tardis_refined.registry.BlockEntityRegistry;
import whocraft.tardis_refined.registry.SoundRegistry;

import static whocraft.tardis_refined.common.block.door.BulkHeadDoorBlock.LOCKED;
import static whocraft.tardis_refined.common.block.door.BulkHeadDoorBlock.OPEN;

public class BulkHeadDoorBlockEntity extends BlockEntity implements BlockEntityTicker<BulkHeadDoorBlockEntity> {

Expand All @@ -21,12 +26,8 @@ public BulkHeadDoorBlockEntity(BlockPos blockPos, BlockState blockState) {

@Override
public void tick(Level level, BlockPos blockPos, BlockState blockState, BulkHeadDoorBlockEntity blockEntity) {
if (!blockState.getValue(BulkHeadDoorBlock.LOCKED) && blockState.canSurvive(level, blockPos)) {
Player player = level.getNearestPlayer(blockPos.getX(), blockPos.getY(), blockPos.getZ(), 2.5f, false);
if (player != null) {
toggleDoor(level, blockPos, blockState, blockState.getValue(BulkHeadDoorBlock.OPEN));
}
}
Player player = level.getNearestPlayer(blockPos.getX(), blockPos.getY(), blockPos.getZ(), 2.5f, false); toggleDoor(level, blockPos, blockState, player != null);
toggleDoor(level, blockPos, blockState, player != null);
}

/**
Expand All @@ -38,8 +39,16 @@ public void tick(Level level, BlockPos blockPos, BlockState blockState, BulkHead
* @param isOpen The current open state of the door.
*/
public void toggleDoor(Level level, BlockPos blockPos, BlockState blockState, boolean isOpen) {
level.playSound(null, blockPos, SoundEvents.PISTON_CONTRACT, SoundSource.BLOCKS, 1, 1);
level.setBlock(blockPos, blockState.setValue(BulkHeadDoorBlock.OPEN, isOpen), Block.UPDATE_CLIENTS);

/* if(blockState.getValue(LOCKED) && !blockState.getValue(OPEN)){
level.playSound(null, blockPos, SoundRegistry.BULKHEAD_LOCKED.get(), SoundSource.BLOCKS, 1, 1);
return;
}*/

if(level.getBlockState(blockPos).hasProperty(OPEN) && level.getBlockState(blockPos).getValue(OPEN) != isOpen) {
level.playSound(null, blockPos, !isOpen ? SoundEvents.PISTON_EXTEND : SoundEvents.PISTON_CONTRACT, SoundSource.BLOCKS, 1, 1);
}
level.setBlock(blockPos, blockState.setValue(OPEN, isOpen), Block.UPDATE_CLIENTS);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void unlockUpgrade(Upgrade upgrade) {
upgrade.onUnlocked(this.tardisLevelOperator, this);

if(this.tardisLevelOperator.getLevel() instanceof ServerLevel serverLevel) {
generateArsTree(serverLevel);
generateArsTree(tardisLevelOperator, serverLevel);
}

TardisEvents.UPGRADE_UNLOCKED.invoker().onUpgradeUnlock(this.tardisLevelOperator, upgrade);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import whocraft.tardis_refined.registry.BlockRegistry;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;

// Responsible for all the tedious generation of the desktop;
public class TardisArchitectureHandler {
Expand All @@ -25,12 +27,14 @@ public class TardisArchitectureHandler {
public static final BlockPos CORRIDOR_ENTRY_POS = new BlockPos(1000, 100, 0);
public static final int INTERIOR_SIZE = 150;

public static String currentArsStage = "one";

public static void generateDesktop(ServerLevel operator, DesktopTheme theme) {
TardisRefined.LOGGER.debug(String.format("Attempting to generate desktop theme: %s for TARDIS.", theme.getIdentifier()));

// Fill the area out.
BlockPos corner = new BlockPos(DESKTOP_CENTER_POS.getX() - INTERIOR_SIZE, operator.getMinBuildHeight() + 75, DESKTOP_CENTER_POS.getZ() - INTERIOR_SIZE);
BlockPos farCorner = new BlockPos(DESKTOP_CENTER_POS.getX() + INTERIOR_SIZE, operator.getMaxBuildHeight() -75, DESKTOP_CENTER_POS.getZ() + INTERIOR_SIZE);
BlockPos farCorner = new BlockPos(DESKTOP_CENTER_POS.getX() + INTERIOR_SIZE, operator.getMaxBuildHeight() - 75, DESKTOP_CENTER_POS.getZ() + INTERIOR_SIZE);

for (BlockPos pos : BlockPos.betweenClosed(corner, farCorner)) {
operator.removeBlock(pos, false);
Expand Down Expand Up @@ -65,8 +69,8 @@ public static void buildAirlockEntranceFromStructure(StructureTemplate template,
TardisLevelOperator.get(level).ifPresent(cap -> {
Optional<StructureTemplate> structureNBT = level.getLevel().getStructureManager().get(new ResourceLocation(TardisRefined.MODID, "corridors/airlock_entrance"));
structureNBT.ifPresent(structure -> {
BlockPos offsetPosition = new BlockPos(3,2,0);
structure.placeInWorld(level.getLevel(), pos.subtract(offsetPosition) , pos.subtract(offsetPosition) , new StructurePlaceSettings(), level.getLevel().random, 3);
BlockPos offsetPosition = new BlockPos(3, 2, 0);
structure.placeInWorld(level.getLevel(), pos.subtract(offsetPosition), pos.subtract(offsetPosition), new StructurePlaceSettings(), level.getLevel().random, 3);

cap.getInteriorManager().setCorridorAirlockCenter(pos.south(2));
level.setBlock(pos, level.getBlockState(pos).setValue(BulkHeadDoorBlock.LOCKED, false), 2);
Expand All @@ -78,34 +82,38 @@ public static void buildAirlockEntranceFromStructure(StructureTemplate template,
}
}

public static void generateEssentialCorridors(ServerLevel operator) {
public static void generateEssentialCorridors(ServerLevel serverLevel) {
// Generate corridor hub
Optional<StructureTemplate> structureNBT = operator.getLevel().getStructureManager().get(new ResourceLocation(TardisRefined.MODID, "corridors/corridor_hub_roomless"));
Optional<StructureTemplate> structureNBT = serverLevel.getLevel().getStructureManager().get(new ResourceLocation(TardisRefined.MODID, "corridors/corridor_hub_roomless"));
structureNBT.ifPresent(structure -> {
BlockPos offsetPosition = new BlockPos(13, 28, 5);
structure.placeInWorld(operator.getLevel(), CORRIDOR_ENTRY_POS.subtract(offsetPosition), CORRIDOR_ENTRY_POS.subtract(offsetPosition), new StructurePlaceSettings(), operator.getLevel().random, 3);
structure.placeInWorld(serverLevel.getLevel(), CORRIDOR_ENTRY_POS.subtract(offsetPosition), CORRIDOR_ENTRY_POS.subtract(offsetPosition), new StructurePlaceSettings(), serverLevel.getLevel().random, 3);
});

generateArsTree(operator);
TardisLevelOperator.get(serverLevel).ifPresent(tardisLevelOperator -> generateArsTree(tardisLevelOperator, serverLevel));

// Generate workshop.
structureNBT = operator.getLevel().getStructureManager().get(new ResourceLocation(TardisRefined.MODID, "rooms/workshop"));
structureNBT = serverLevel.getLevel().getStructureManager().get(new ResourceLocation(TardisRefined.MODID, "rooms/workshop"));
structureNBT.ifPresent(structure -> {
BlockPos position = new BlockPos(977,99,9);
structure.placeInWorld(operator.getLevel(), position, position, new StructurePlaceSettings(), operator.getLevel().random, Block.UPDATE_ALL);
BlockPos position = new BlockPos(977, 99, 9);
structure.placeInWorld(serverLevel.getLevel(), position, position, new StructurePlaceSettings(), serverLevel.getLevel().random, Block.UPDATE_ALL);
});

}

public static void generateArsTree(ServerLevel level) {
TardisLevelOperator.get(level).ifPresent(tardisLevelOperator -> {
Optional<StructureTemplate> structureNBT = level.getLevel().getStructureManager().get(new ResourceLocation(TardisRefined.MODID, "rooms/ars/room_ars_stage_" + tardisLevelOperator.getUpgradeHandler().getProgressLevel()));
structureNBT.ifPresent(structure -> {
BlockPos position = new BlockPos(1011,97,3);
structure.placeInWorld(level.getLevel(), position, position, new StructurePlaceSettings(), level.getLevel().random, Block.UPDATE_ALL);
});
public static void generateArsTree(TardisLevelOperator tardisLevelOperator, ServerLevel level) {
if (!currentArsStage.equals("one") && Objects.equals(tardisLevelOperator.getUpgradeHandler().getProgressLevel(), currentArsStage))
return;

currentArsStage = tardisLevelOperator.getUpgradeHandler().getProgressLevel();

Optional<StructureTemplate> structureNBT = level.getLevel().getStructureManager().get(new ResourceLocation(TardisRefined.MODID, "rooms/ars/room_ars_stage_" + currentArsStage));
structureNBT.ifPresent(structure -> {
BlockPos position = new BlockPos(1011, 97, 3);
structure.placeInWorld(level.getLevel(), position, position, new StructurePlaceSettings(), level.getLevel().random, Block.UPDATE_ALL);
});


}

public static boolean setInteriorDoorFromStructure(StructureTemplate template, ServerLevel level) {
Expand All @@ -114,7 +122,7 @@ public static boolean setInteriorDoorFromStructure(StructureTemplate template, S
BlockPos maxPos = new BlockPos(minPos.getX() + template.getSize().getX(),
minPos.getY() + template.getSize().getY(),
minPos.getZ() + template.getSize().getZ()
);
);

//First set the internal door to null so that we aren't caching the previous desktop's internal door
TardisLevelOperator.get(level).ifPresent(cap -> cap.setInternalDoor(null));
Expand All @@ -129,7 +137,7 @@ public static boolean setInteriorDoorFromStructure(StructureTemplate template, S
}

public static BlockPos calculateArcOffset(StructureTemplate structureTemplate, BlockPos centerPos) {
return new BlockPos(centerPos.getX() - structureTemplate.getSize().getX() / 2, centerPos.getY() - structureTemplate.getSize().getY() / 2,centerPos.getZ() - structureTemplate.getSize().getZ() / 2);
return new BlockPos(centerPos.getX() - structureTemplate.getSize().getX() / 2, centerPos.getY() - structureTemplate.getSize().getY() / 2, centerPos.getZ() - structureTemplate.getSize().getZ() / 2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class SoundRegistry {
public static final RegistrySupplier<SoundEvent> STATIC = setUpSound("static");
public static final RegistrySupplier<SoundEvent> DESTINATION_DING = setUpSound("destination_ding");
public static final RegistrySupplier<SoundEvent> ARS_HUM = setUpSound("ars_hum");
public static final RegistrySupplier<SoundEvent> BULKHEAD_LOCKED = setUpSound("bulkhead_locked");
public static final RegistrySupplier<SoundEvent> TEST_HUM = setUpSound("test_hum");

private static RegistrySupplier<SoundEvent> setUpSound(String soundName) {
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.2 2023-12-15T23:31:01.2684 Sound Definitions
af46e2a431d190adcb7142234979fa721ca75855 assets/tardis_refined/sounds.json
// 1.20.2 2023-12-22T14:44:08.8631383 Sound Definitions
4875e9832141aea2449ebba45177460bb6eed8a0 assets/tardis_refined/sounds.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.2 2023-12-21T01:13:46.4354098 Languages: en_us
b3b6b26fd2fb1d1a118a3fda307b43f323efaf3b assets/tardis_refined/lang/en_us.json
// 1.20.2 2023-12-22T14:44:08.8611045 Languages: en_us
0afdb1f9c0785ed6cce4beba2ed9d9e69890bb98 assets/tardis_refined/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
],
"subtitle": "sound.ars_hum.subtitle"
},
"bulkhead_locked": {
"sounds": [
"tardis_refined:blocks/bulkhead_locked"
],
"subtitle": "sound.bulkhead_locked.subtitle"
},
"destination_ding": {
"sounds": [
"tardis_refined:tardis/destination_ding"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void registerSounds() {
add(SoundRegistry.STATIC.get(), basicSound("static", new ResourceLocation(TardisRefined.MODID, "ui/static")));
add(SoundRegistry.DESTINATION_DING.get(), basicSound("destination_ding", new ResourceLocation(TardisRefined.MODID, "tardis/destination_ding")));
add(SoundRegistry.ARS_HUM.get(), basicSound("ars_hum", new ResourceLocation(TardisRefined.MODID, "tardis/ars/ars_hum")));
add(SoundRegistry.BULKHEAD_LOCKED.get(), basicSound("bulkhead_locked", new ResourceLocation(TardisRefined.MODID, "blocks/bulkhead_locked")));
add(SoundRegistry.TEST_HUM.get(), basicSound("test_hum", new ResourceLocation(TardisRefined.MODID, "tardis/test_hum")));
}

Expand Down

0 comments on commit a7c6db5

Please sign in to comment.