Skip to content

Commit

Permalink
Shell lights based on what the model looks like (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
CommandrMoose authored Mar 30, 2024
1 parent a96000c commit 7d9b648
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,39 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
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.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import whocraft.tardis_refined.common.blockentity.shell.GlobalShellBlockEntity;
import whocraft.tardis_refined.common.blockentity.shell.ShellBaseBlockEntity;
import whocraft.tardis_refined.common.capability.TardisLevelOperator;
import whocraft.tardis_refined.common.tardis.themes.ShellTheme;

public class GlobalShellBlock extends ShellBaseBlock{

public static final BooleanProperty LIT = BooleanProperty.create("lit");

public GlobalShellBlock(Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(OPEN, false).setValue(WATERLOGGED, false).setValue(LOCKED, false));
}

@Override
public int getLightBlock(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos) {
return super.getLightBlock(blockState, blockGetter, blockPos);
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(OPEN, false).setValue(WATERLOGGED, false).setValue(LOCKED, false).setValue(LIT, false));
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(LIT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
package whocraft.tardis_refined.common.blockentity.shell;

import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import whocraft.tardis_refined.TardisRefined;
import whocraft.tardis_refined.common.block.shell.GlobalShellBlock;
import whocraft.tardis_refined.common.block.shell.ShellBaseBlock;
import whocraft.tardis_refined.common.capability.TardisLevelOperator;
import whocraft.tardis_refined.common.dimension.DimensionHandler;
import whocraft.tardis_refined.common.items.KeyItem;
import whocraft.tardis_refined.common.tardis.themes.ShellTheme;
import whocraft.tardis_refined.common.util.RegistryHelper;
import whocraft.tardis_refined.constants.NbtConstants;
import whocraft.tardis_refined.constants.ResourceConstants;
import whocraft.tardis_refined.patterns.ShellPattern;
import whocraft.tardis_refined.patterns.ShellPatterns;
import whocraft.tardis_refined.registry.BlockEntityRegistry;
Expand All @@ -30,7 +25,6 @@
public class GlobalShellBlockEntity extends ShellBaseBlockEntity {

private ResourceLocation shellTheme;

private ShellPattern basePattern;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ public void setShellTheme(ResourceLocation theme, boolean setupTardis, TardisNav

// Check if its our default global shell.
if (state.getBlock() instanceof GlobalShellBlock globalShellBlock) {
lastKnownLocationLevel.setBlock(lastKnownLocationPosition, state.setValue(GlobalShellBlock.REGEN, false), Block.UPDATE_CLIENTS);

ShellTheme shellTheme = ShellTheme.getShellTheme(theme);
boolean shouldProduceLight = shellTheme.producesLight();

lastKnownLocationLevel.setBlock(lastKnownLocationPosition, state.setValue(GlobalShellBlock.REGEN, false).setValue(GlobalShellBlock.LIT, shouldProduceLight), Block.UPDATE_CLIENTS);

// Update Exterior (We should make this a method tbh)
updateShellBlock(theme, lastKnownLocationLevel, lastKnownLocationPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,13 @@ public void removeExteriorBlock() {
public void placeExteriorBlock(TardisLevelOperator operator, TardisNavLocation location) {
AestheticHandler aestheticHandler = operator.getAestheticHandler();
ResourceLocation theme = (aestheticHandler.getShellTheme() != null) ? aestheticHandler.getShellTheme() : ShellTheme.FACTORY.getId();
ShellTheme shellTheme = ShellTheme.getShellTheme(theme);

BlockState targetBlockState = BlockRegistry.GLOBAL_SHELL_BLOCK.get().defaultBlockState()
.setValue(GlobalShellBlock.FACING, location.getDirection())
.setValue(GlobalShellBlock.REGEN, false)
.setValue(LOCKED, operator.getExteriorManager().locked)
.setValue(GlobalShellBlock.LIT, shellTheme.producesLight())
.setValue(GlobalShellBlock.WATERLOGGED, location.getLevel().getBlockState(location.getPosition()).getFluidState().getType() == Fluids.WATER);

ServerLevel targetLevel = location.getLevel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ public class ShellTheme implements Theme {
public static final Registry<ShellTheme> SHELL_THEME_REGISTRY = SHELL_THEMES.getRegistry();

public static final RegistrySupplierHolder<ShellTheme, ShellTheme> FACTORY = registerShellTheme("factory");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> POLICE_BOX = registerShellTheme("police_box");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> PHONE_BOOTH = registerShellTheme("phone_booth");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> MYSTIC = registerShellTheme("mystic");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> POLICE_BOX = registerShellTheme("police_box", true);
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> PHONE_BOOTH = registerShellTheme("phone_booth", true);
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> MYSTIC = registerShellTheme("mystic", true);
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> PRESENT = registerShellTheme("present");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> DRIFTER = registerShellTheme("drifter");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> VENDING = registerShellTheme("vending");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> VENDING = registerShellTheme("vending", true);
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> BRIEFCASE = registerShellTheme("briefcase");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> GROENING = registerShellTheme("groening");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> BIG_BEN = registerShellTheme("big_ben");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> NUKA = registerShellTheme("nuka");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> GROENING = registerShellTheme("groening", true);
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> BIG_BEN = registerShellTheme("big_ben", true);
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> NUKA = registerShellTheme("nuka", true);
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> GROWTH = registerShellTheme("growth");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> PORTALOO = registerShellTheme("portaloo");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> PAGODA = registerShellTheme("pagoda");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> LIFT = registerShellTheme("lift");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> LIFT = registerShellTheme("lift", true);
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> HIEROGLYPH = registerShellTheme("hieroglyph");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> CASTLE = registerShellTheme("castle");
public static final RegistrySupplierHolder<ShellTheme, ShellTheme> PATHFINDER = registerShellTheme("pathfinder");
Expand All @@ -53,13 +53,24 @@ public static ResourceLocation getKey(ShellTheme shellTheme){
}

private ResourceLocation translationKey;
private boolean producesLight;

public ShellTheme(ResourceLocation translationKey){ this.translationKey = translationKey;}
public ShellTheme(ResourceLocation translationKey) {
this.translationKey = translationKey;
}
public ShellTheme(ResourceLocation translationKey, boolean producesLight) {
this.translationKey = translationKey;
this.producesLight = producesLight;
}

private static RegistrySupplierHolder<ShellTheme, ShellTheme> registerShellTheme(String id){
return SHELL_THEMES.registerHolder(id, () -> new ShellTheme(new ResourceLocation(TardisRefined.MODID, id)));
}

private static RegistrySupplierHolder<ShellTheme, ShellTheme> registerShellTheme(String id, boolean producesLight){
return SHELL_THEMES.registerHolder(id, () -> new ShellTheme(new ResourceLocation(TardisRefined.MODID, id), producesLight));
}

@Override
public String getTranslationKey() {
return Util.makeDescriptionId("shell", this.translationKey);
Expand All @@ -70,4 +81,8 @@ public Component getDisplayName() {
return Component.translatable(this.getTranslationKey());
}

public boolean producesLight() {
return producesLight;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ private static <T extends Block> RegistrySupplier<T> register(String id, Supplie

// Shell Blocks
public static final RegistrySupplier<ShellBaseBlock> ROOT_SHELL_BLOCK = register("root_shell", () -> new RootedShellBlock(BlockBehaviour.Properties.of().noOcclusion().strength(1000, 1000).sound(SoundType.CORAL_BLOCK)), true, true);
public static final RegistrySupplier<ShellBaseBlock> GLOBAL_SHELL_BLOCK = register("tardis_shell", () -> new GlobalShellBlock(BlockBehaviour.Properties.of().noOcclusion().strength(1000, 1000).sound(SoundType.STONE)), false, false);
public static final RegistrySupplier<ShellBaseBlock> GLOBAL_SHELL_BLOCK = register("tardis_shell", () -> new GlobalShellBlock(BlockBehaviour.Properties.of().noOcclusion().strength(1000, 1000).sound(SoundType.STONE).lightLevel((blocksState) -> {
return blocksState.getValue(GlobalShellBlock.LIT) ? 13 : 0;
})), false, false);

// Interior
public static final RegistrySupplier<GlobalDoorBlock> GLOBAL_DOOR_BLOCK = register("tardis_door", () -> new GlobalDoorBlock(BlockBehaviour.Properties.of().noOcclusion().strength(10, 10).sound(SoundType.STONE)), true, true);
Expand Down

0 comments on commit 7d9b648

Please sign in to comment.