i hate block entities

This commit is contained in:
gamma-delta 2022-03-20 16:50:19 -05:00
parent f99ccfe8d9
commit aadfc835df
20 changed files with 277 additions and 205 deletions

View file

@ -1,6 +1,6 @@
6cddedaeedb02a0a10f7d3b32a5a22ee133407ec assets/hexcasting/blockstates/impetus_rightclick.json
6ffdff8f82bab364cacdcad8aecaead9028ce4d1 assets/hexcasting/blockstates/impetus_rightclick.json
e26f9f72db9fab9b78bad75ec4c1746b4f84fa12 assets/hexcasting/blockstates/slate.json
043abd5bbfd1186415049d24d185d4e4395320f9 assets/hexcasting/blockstates/slate_block.json
e26f9f72db9fab9b78bad75ec4c1746b4f84fa12 assets/hexcasting/blockstates/slate_written.json
aa21181c678331a51488a4afc1495489fb949ae6 assets/hexcasting/models/block/impetus_rightclick.json
5644693cfd0552f0afd5d7491dd8fb196f1e177f assets/hexcasting/models/block/impetus_rightclick_lit.json
d51541b464840530f4e734db1f67ed20e811ad14 assets/hexcasting/models/block/slate_block.json
@ -78,6 +78,7 @@ e7b88cde507911c0ad1bf60976dcc43a319d498d assets/hexcasting/models/item/pride_col
9ef07e2885063ed1ffe1cb8f7728f26cb7c9881e assets/hexcasting/models/item/scroll.json
297b05008b9ab37b5881820a0f5c99f7441a9dfe assets/hexcasting/models/item/scroll_ancient.json
91765bdc3a764f3a3f10131e452a0030b207b03d assets/hexcasting/models/item/scroll_pristine.json
d06214a759ea5db686cdc5982baa74e1bd678815 assets/hexcasting/models/item/slate.json
e7aa1f9b9eaf20cbeb19eaf9cb96f3276eca6dfd assets/hexcasting/models/item/slate_blank.json
cc66962ddeef9b9c3a623eef178b352605f1c922 assets/hexcasting/models/item/slate_block.json
1b61e7b2d78d4c8a2f1af6fb5c69ac4ac55abd50 assets/hexcasting/models/item/slate_written.json

View file

@ -1,39 +1,39 @@
{
"variants": {
"facing=north,lit=false": {
"energized=false,facing=north": {
"model": "hexcasting:block/impetus_rightclick",
"uvlock": true
},
"facing=south,lit=false": {
"energized=true,facing=north": {
"model": "hexcasting:block/impetus_rightclick_lit",
"uvlock": true
},
"energized=false,facing=south": {
"model": "hexcasting:block/impetus_rightclick",
"y": 180,
"uvlock": true
},
"facing=west,lit=false": {
"energized=true,facing=south": {
"model": "hexcasting:block/impetus_rightclick_lit",
"y": 180,
"uvlock": true
},
"energized=false,facing=west": {
"model": "hexcasting:block/impetus_rightclick",
"y": 270,
"uvlock": true
},
"facing=east,lit=false": {
"energized=true,facing=west": {
"model": "hexcasting:block/impetus_rightclick_lit",
"y": 270,
"uvlock": true
},
"energized=false,facing=east": {
"model": "hexcasting:block/impetus_rightclick",
"y": 90,
"uvlock": true
},
"facing=north,lit=true": {
"model": "hexcasting:block/impetus_rightclick_lit",
"uvlock": true
},
"facing=south,lit=true": {
"model": "hexcasting:block/impetus_rightclick_lit",
"y": 180,
"uvlock": true
},
"facing=west,lit=true": {
"model": "hexcasting:block/impetus_rightclick_lit",
"y": 270,
"uvlock": true
},
"facing=east,lit=true": {
"energized=true,facing=east": {
"model": "hexcasting:block/impetus_rightclick_lit",
"y": 90,
"uvlock": true

View file

@ -0,0 +1,16 @@
{
"overrides": [
{
"predicate": {
"hexcasting:written": 0.0
},
"model": "hexcasting:item/slate_blank"
},
{
"predicate": {
"hexcasting:written": 1.0
},
"model": "hexcasting:item/slate_written"
}
]
}

View file

@ -3,7 +3,6 @@ package at.petrak.hexcasting.api;
import at.petrak.hexcasting.hexmath.HexPattern;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
@ -11,6 +10,8 @@ import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import org.jetbrains.annotations.Nullable;
import java.util.EnumSet;
public abstract class BlockCircleComponent extends Block {
public static final BooleanProperty ENERGIZED = BooleanProperty.create("energized");
@ -18,10 +19,12 @@ public abstract class BlockCircleComponent extends Block {
super(p_49795_);
}
abstract public Direction[] exitDirections(BlockPos pos, BlockState bs, ServerLevel world);
abstract public boolean canEnterFromDirection(Direction enterDir, BlockPos pos, BlockState bs, Level world);
abstract public EnumSet<Direction> exitDirections(BlockPos pos, BlockState bs, Level world);
@Nullable
abstract public HexPattern getPattern(BlockPos pos, BlockState bs, ServerLevel world);
abstract public HexPattern getPattern(BlockPos pos, BlockState bs, Level world);
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {

View file

@ -4,6 +4,7 @@ import at.petrak.hexcasting.client.gui.PatternTooltipGreeble;
import at.petrak.hexcasting.common.blocks.circles.BlockEntitySlate;
import at.petrak.hexcasting.common.items.HexItems;
import at.petrak.hexcasting.common.items.ItemScroll;
import at.petrak.hexcasting.common.items.ItemSlate;
import at.petrak.hexcasting.hexmath.HexPattern;
import com.mojang.datafixers.util.Either;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
@ -41,14 +42,15 @@ public class HexTooltips {
tag.contains(ItemScroll.TAG_OP_ID)
? PatternTooltipGreeble.ANCIENT_BG : PatternTooltipGreeble.PRISTINE_BG)));
}
} else if (stack.is(HexItems.WRITTEN_SLATE.get())) {
var tag = stack.getOrCreateTag();
if (tag.contains(BlockEntitySlate.TAG_PATTERN)) {
var pattern = HexPattern.DeserializeFromNBT(tag.getCompound(BlockEntitySlate.TAG_PATTERN));
evt.getTooltipElements().add(Either.right(new PatternTooltipGreeble(
pattern,
PatternTooltipGreeble.SLATE_BG)));
}
} else if (stack.is(HexItems.SLATE.get()) && ItemSlate.hasPattern(stack)) {
var tag = stack.getOrCreateTag()
.getCompound("BlockEntityTag")
.getCompound(BlockEntitySlate.TAG_PATTERN);
var pattern = HexPattern.DeserializeFromNBT(tag);
evt.getTooltipElements().add(Either.right(new PatternTooltipGreeble(
pattern,
PatternTooltipGreeble.SLATE_BG)));
}
}
}

View file

@ -8,6 +8,7 @@ import at.petrak.hexcasting.common.blocks.circles.BlockEntitySlate;
import at.petrak.hexcasting.common.items.HexItems;
import at.petrak.hexcasting.common.items.ItemFocus;
import at.petrak.hexcasting.common.items.ItemScroll;
import at.petrak.hexcasting.common.items.ItemSlate;
import at.petrak.hexcasting.common.items.magic.ItemManaBattery;
import at.petrak.hexcasting.common.items.magic.ItemPackagedSpell;
import at.petrak.hexcasting.common.particles.HexParticles;
@ -78,6 +79,9 @@ public class RegisterClientStuff {
ItemProperties.register(HexItems.SCROLL.get(), ItemScroll.ANCIENT_PREDICATE,
(stack, level, holder, holderID) -> stack.getOrCreateTag().contains(ItemScroll.TAG_OP_ID) ? 1f : 0f);
ItemProperties.register(HexItems.SLATE.get(), ItemSlate.WRITTEN_PRED,
(stack, level, holder, holderID) -> ItemSlate.hasPattern(stack) ? 1f : 0f);
HexTooltips.init();
});

View file

@ -4,19 +4,13 @@ import at.petrak.hexcasting.common.casting.colors.FrozenColorizer;
import at.petrak.hexcasting.common.particles.ConjureParticleOptions;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
import java.util.Random;
public class BlockEntityConjured extends BlockEntity {
public class BlockEntityConjured extends ModBlockEntity {
private static final Random RANDOM = new Random();
private FrozenColorizer colorizer = FrozenColorizer.DEFAULT;
@ -91,14 +85,15 @@ public class BlockEntityConjured extends BlockEntity {
}
@Override
public void saveAdditional(CompoundTag pTag) {
pTag.put(TAG_COLORIZER, this.colorizer.serialize());
super.saveAdditional(pTag);
protected void saveModData(CompoundTag tag) {
tag.put(TAG_COLORIZER, this.colorizer.serialize());
}
public void load(@NotNull CompoundTag tag) {
super.load(tag);
readPacketNBT(tag);
@Override
protected void loadModData(CompoundTag tag) {
if (tag.contains(TAG_COLORIZER)) {
this.setColorizer(FrozenColorizer.deserialize(tag.getCompound(TAG_COLORIZER)));
}
}
public FrozenColorizer getColorizer() {
@ -110,32 +105,22 @@ public class BlockEntityConjured extends BlockEntity {
this.setChanged();
}
@Override
public void setChanged() {
if (this.level == null) {
return;
}
this.level.sendBlockUpdated(this.worldPosition, this.getBlockState(), this.getBlockState(),
Block.UPDATE_CLIENTS);
super.setChanged();
}
public void readPacketNBT(CompoundTag tag) {
if (tag.contains(TAG_COLORIZER)) {
this.setColorizer(FrozenColorizer.deserialize(tag.getCompound(TAG_COLORIZER)));
}
}
public ClientboundBlockEntityDataPacket getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this);
}
@Override
public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) {
this.load(Objects.requireNonNull(pkt.getTag()));
}
public @NotNull CompoundTag getUpdateTag() {
return this.saveWithoutMetadata();
}
// @Override
// public void setChanged() {
// if (this.level == null) {
// return;
// }
// this.level.sendBlockUpdated(this.worldPosition, this.getBlockState(), this.getBlockState(),
// Block.UPDATE_CLIENTS);
// super.setChanged();
// }
//
// public ClientboundBlockEntityDataPacket getUpdatePacket() {
// return ClientboundBlockEntityDataPacket.create(this);
// }
//
// @Override
// public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) {
// this.load(Objects.requireNonNull(pkt.getTag()));
// }
}

View file

@ -34,7 +34,7 @@ public class HexBlocks {
.isSuffocating(HexBlocks::never)
.isViewBlocking(HexBlocks::never)));
public static final RegistryObject<Block> WRITTEN_SLATE = BLOCKS.register("slate_written",
public static final RegistryObject<Block> SLATE = BLOCKS.register("slate",
() -> new BlockSlate(BlockBehaviour.Properties.of(Material.STONE, MaterialColor.DEEPSLATE)
.sound(SoundType.DEEPSLATE_TILES)
.strength(2f, 4f)));
@ -42,7 +42,7 @@ public class HexBlocks {
new BlockRightClickImpetus(BlockBehaviour.Properties.of(Material.STONE, MaterialColor.DEEPSLATE)
.sound(SoundType.DEEPSLATE_TILES)
.strength(2f, 4f)
.lightLevel(bs -> bs.getValue(BlockAbstractImpetus.LIT) ? 15 : 0)));
.lightLevel(bs -> bs.getValue(BlockAbstractImpetus.ENERGIZED) ? 15 : 0)));
// Decoration?!
public static final RegistryObject<Block> SLATE_BLOCK = registerBlock("slate_block",
@ -54,8 +54,8 @@ public class HexBlocks {
"conjured_tile",
() -> BlockEntityType.Builder.of(BlockEntityConjured::new, CONJURED.get()).build(null));
public static final RegistryObject<BlockEntityType<BlockEntitySlate>> SLATE_TILE = BLOCK_ENTITIES.register(
"slate_written_tile",
() -> BlockEntityType.Builder.of(BlockEntitySlate::new, WRITTEN_SLATE.get()).build(null));
"slate_tile",
() -> BlockEntityType.Builder.of(BlockEntitySlate::new, SLATE.get()).build(null));
public static final RegistryObject<BlockEntityType<BlockEntityRightClickImpetus>> IMPETUS_RIGHTCLICK_TILE =
BLOCK_ENTITIES.register("impetus_rightclick_tile",
() -> BlockEntityType.Builder.of(BlockEntityRightClickImpetus::new, IMPETUS_RIGHTCLICK.get()).build(null));

View file

@ -0,0 +1,40 @@
package at.petrak.hexcasting.common.blocks;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
public abstract class ModBlockEntity extends BlockEntity {
public ModBlockEntity(BlockEntityType<?> pType, BlockPos pWorldPosition, BlockState pBlockState) {
super(pType, pWorldPosition, pBlockState);
}
protected abstract void saveModData(CompoundTag tag);
protected abstract void loadModData(CompoundTag tag);
@Override
protected void saveAdditional(CompoundTag pTag) {
saveModData(pTag);
}
@Override
public void load(CompoundTag pTag) {
super.load(pTag);
loadModData(pTag);
}
@Override
public CompoundTag getUpdateTag() {
var tag = new CompoundTag();
saveModData(tag);
return tag;
}
@Override
public void handleUpdateTag(CompoundTag tag) {
loadModData(tag);
}
}

View file

@ -2,6 +2,7 @@ package at.petrak.hexcasting.common.blocks.circles;
import at.petrak.hexcasting.client.RenderLib;
import at.petrak.hexcasting.common.blocks.HexBlocks;
import at.petrak.hexcasting.common.blocks.ModBlockEntity;
import at.petrak.hexcasting.hexmath.HexPattern;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
@ -15,12 +16,11 @@ import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Mth;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec2;
import org.jetbrains.annotations.Nullable;
public class BlockEntitySlate extends BlockEntity {
public class BlockEntitySlate extends ModBlockEntity {
public static final String TAG_PATTERN = "pattern";
@Nullable
@ -31,26 +31,19 @@ public class BlockEntitySlate extends BlockEntity {
}
@Override
protected void saveAdditional(CompoundTag tag) {
protected void saveModData(CompoundTag tag) {
if (this.pattern != null) {
tag.put(TAG_PATTERN, this.pattern.serializeToNBT());
}
}
@Override
public CompoundTag getUpdateTag() {
var out = new CompoundTag();
this.saveAdditional(out);
return out;
}
@Override
public void load(CompoundTag tag) {
super.load(tag);
protected void loadModData(CompoundTag tag) {
if (tag.contains(TAG_PATTERN)) {
this.pattern = HexPattern.DeserializeFromNBT(tag.getCompound(TAG_PATTERN));
}
}
public static class Renderer implements BlockEntityRenderer<BlockEntitySlate> {
private final BlockRenderDispatcher dispatcher;

View file

@ -4,9 +4,6 @@ import at.petrak.hexcasting.api.BlockCircleComponent;
import at.petrak.hexcasting.hexmath.HexPattern;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
@ -25,6 +22,8 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import java.util.EnumSet;
// FACING is the direction the *bottom* of the pattern points
// (or which way is "down")
public class BlockSlate extends BlockCircleComponent implements EntityBlock {
@ -40,12 +39,17 @@ public class BlockSlate extends BlockCircleComponent implements EntityBlock {
}
@Override
public Direction[] exitDirections(BlockPos pos, BlockState bs, ServerLevel world) {
return new Direction[]{Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST};
public boolean canEnterFromDirection(Direction enterDir, BlockPos pos, BlockState bs, Level world) {
return enterDir != Direction.UP;
}
@Override
public @Nullable HexPattern getPattern(BlockPos pos, BlockState bs, ServerLevel world) {
public EnumSet<Direction> exitDirections(BlockPos pos, BlockState bs, Level world) {
return EnumSet.of(Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST);
}
@Override
public @Nullable HexPattern getPattern(BlockPos pos, BlockState bs, Level world) {
if (world.getBlockEntity(pos) instanceof BlockEntitySlate tile) {
return tile.pattern;
} else {
@ -59,16 +63,6 @@ public class BlockSlate extends BlockCircleComponent implements EntityBlock {
return new BlockEntitySlate(pPos, pState);
}
@Override
public void setPlacedBy(Level pLevel, BlockPos pPos, BlockState pState, @Nullable LivingEntity pPlacer,
ItemStack pStack) {
if (pLevel.getBlockEntity(pPos) instanceof BlockEntitySlate tile) {
var patTag = pStack.getOrCreateTag().getCompound(BlockEntitySlate.TAG_PATTERN);
tile.pattern = HexPattern.DeserializeFromNBT(patTag);
tile.setChanged();
}
}
@Override
public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
return AABB_FLOOR;

View file

@ -6,6 +6,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.Mirror;
@ -16,6 +17,7 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import org.jetbrains.annotations.Nullable;
import java.util.EnumSet;
import java.util.Random;
// Facing dir is the direction it starts searching for slates in to start
@ -29,12 +31,17 @@ public abstract class BlockAbstractImpetus extends BlockCircleComponent implemen
}
@Override
public Direction[] exitDirections(BlockPos pos, BlockState bs, ServerLevel world) {
return new Direction[]{bs.getValue(FACING)};
public boolean canEnterFromDirection(Direction enterDir, BlockPos pos, BlockState bs, Level world) {
return true;
}
@Override
public @Nullable HexPattern getPattern(BlockPos pos, BlockState bs, ServerLevel world) {
public EnumSet<Direction> exitDirections(BlockPos pos, BlockState bs, Level world) {
return EnumSet.of(bs.getValue(FACING));
}
@Override
public @Nullable HexPattern getPattern(BlockPos pos, BlockState bs, Level world) {
return null;
}

View file

@ -1,10 +1,9 @@
package at.petrak.hexcasting.common.blocks.circles.impetuses;
import at.petrak.hexcasting.HexConfig;
import at.petrak.hexcasting.api.BlockCircleComponent;
import at.petrak.hexcasting.api.ParticleSpray;
import at.petrak.hexcasting.common.blocks.HexBlocks;
import at.petrak.hexcasting.common.blocks.circles.BlockEntitySlate;
import at.petrak.hexcasting.common.blocks.circles.BlockSlate;
import at.petrak.hexcasting.common.blocks.ModBlockEntity;
import at.petrak.hexcasting.common.casting.CastingContext;
import at.petrak.hexcasting.common.casting.CastingHarness;
import at.petrak.hexcasting.common.casting.colors.FrozenColorizer;
@ -12,7 +11,6 @@ import at.petrak.hexcasting.common.items.HexItems;
import at.petrak.hexcasting.common.lib.HexCapabilities;
import at.petrak.hexcasting.common.lib.HexSounds;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils;
@ -26,7 +24,6 @@ import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
@ -36,7 +33,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public abstract class BlockEntityAbstractImpetus extends BlockEntity {
public abstract class BlockEntityAbstractImpetus extends ModBlockEntity {
public static final String
TAG_ACTIVATOR = "activator",
TAG_COLORIZER = "colorizer",
@ -69,7 +66,7 @@ public abstract class BlockEntityAbstractImpetus extends BlockEntity {
this.level.scheduleTick(this.getBlockPos(), this.getBlockState().getBlock(), this.getTickSpeed());
this.activator = activator.getUUID();
this.nextBlock = this.getBlockPos().above();
this.nextBlock = this.getBlockPos();
this.trackedBlocks = new ArrayList<>();
var maybeCap = activator.getCapability(HexCapabilities.PREFERRED_COLORIZER).resolve();
maybeCap.ifPresent(capPreferredColorizer -> this.colorizer = capPreferredColorizer.colorizer);
@ -100,48 +97,58 @@ public abstract class BlockEntityAbstractImpetus extends BlockEntity {
return;
}
// This should only fail if we remove blocks halfway through casting
var bsHere = this.level.getBlockState(this.nextBlock);
if (!this.trackedBlocks.isEmpty() && bsHere.getBlock() instanceof BlockAbstractImpetus) {
// no two impetuses!
this.errorEffect(Vec3.atBottomCenterOf(this.nextBlock));
this.stopCasting();
return;
}
var blockHere = bsHere.getBlock();
if (!(blockHere instanceof BlockCircleComponent cc)) {
this.errorEffect(Vec3.atBottomCenterOf(this.nextBlock));
this.stopCasting();
return;
}
// Awesome we know this block is OK
if (this.trackedBlocks.isEmpty()) {
// then this is the very first activation!
this.trackedBlocks.add(this.nextBlock);
// and shunt it along by one
this.nextBlock = this.nextBlock.relative(this.getBlockState().getValue(BlockAbstractImpetus.FACING));
} else {
BlockPos foundPos = null;
for (var dir : HORIZONTAL_DIRS) {
var neighborPos = this.nextBlock.relative(dir);
var blockThere = this.level.getBlockState(neighborPos);
// at this point, we haven't actually added nextBlock to trackedBlocks
// so, in the smallest circle case (a 2x2), this will have a size of 3 (with this block being the 4th).
var closedLoop = (this.trackedBlocks.size() >= 3 && this.trackedBlocks.get(0).equals(neighborPos));
var mightBeOkThere = closedLoop || !this.trackedBlocks.contains(neighborPos);
if (mightBeOkThere && blockThere.is(HexBlocks.WRITTEN_SLATE.get())) {
if (foundPos == null) {
foundPos = neighborPos;
this.foundAll |= closedLoop;
} else {
// uh oh, fork in the road
this.errorEffect(Vec3.atBottomCenterOf(this.nextBlock));
this.stopCasting();
return;
}
var possibleExits = cc.exitDirections(this.nextBlock, bsHere, this.level);
BlockPos foundPos = null;
for (var exit : possibleExits) {
var neighborPos = this.nextBlock.relative(exit);
var blockThere = this.level.getBlockState(neighborPos);
// at this point, we haven't actually added nextBlock to trackedBlocks
// so, in the smallest circle case (a 2x2), this will have a size of 3 (with this block being the 4th).
var closedLoop = (this.trackedBlocks.size() >= 3 && this.trackedBlocks.get(0).equals(neighborPos));
var mightBeOkThere = closedLoop || !this.trackedBlocks.contains(neighborPos);
if (mightBeOkThere
&& blockThere.getBlock() instanceof BlockCircleComponent cc2
&& cc2.canEnterFromDirection(exit, neighborPos, blockThere, this.level)) {
if (foundPos == null) {
foundPos = neighborPos;
this.foundAll |= closedLoop;
} else {
// uh oh, fork in the road
this.errorEffect(Vec3.atBottomCenterOf(this.nextBlock));
this.stopCasting();
return;
}
}
if (foundPos != null) {
// pog
this.trackedBlocks.add(this.nextBlock);
this.nextBlock = foundPos;
} else {
// end of the line
this.errorEffect(Vec3.atBottomCenterOf(this.nextBlock));
this.stopCasting();
return;
}
}
if (foundPos != null) {
// pog
this.trackedBlocks.add(this.nextBlock);
this.nextBlock = foundPos;
} else {
// end of the line
this.errorEffect(Vec3.atBottomCenterOf(this.nextBlock));
this.stopCasting();
return;
}
var lastPos = this.trackedBlocks.get(this.trackedBlocks.size() - 1);
var justTrackedBlock = this.level.getBlockState(lastPos);
this.level.setBlockAndUpdate(lastPos, justTrackedBlock.setValue(BlockSlate.LIT, true));
this.level.setBlockAndUpdate(lastPos, justTrackedBlock.setValue(BlockCircleComponent.ENERGIZED, true));
this.successEffect(Vec3.atBottomCenterOf(lastPos));
this.level.scheduleTick(this.getBlockPos(), this.getBlockState().getBlock(), this.getTickSpeed());
@ -154,11 +161,15 @@ public abstract class BlockEntityAbstractImpetus extends BlockEntity {
var ctx = new CastingContext(splayer, InteractionHand.MAIN_HAND);
var harness = new CastingHarness(ctx);
for (var tracked : this.trackedBlocks) {
if (this.level.getBlockEntity(tracked) instanceof BlockEntitySlate slate) {
var info = harness.executeNewPattern(slate.pattern, splayer.getLevel());
if (info.getWasPrevPatternInvalid()) {
this.errorEffect(Vec3.atBottomCenterOf(tracked));
break;
var bs = this.level.getBlockState(tracked);
if (bs.getBlock() instanceof BlockCircleComponent cc) {
var newPattern = cc.getPattern(tracked, bs, this.level);
if (newPattern != null) {
var info = harness.executeNewPattern(newPattern, splayer.getLevel());
if (info.getWasPrevPatternInvalid()) {
this.errorEffect(Vec3.atBottomCenterOf(tracked));
break;
}
}
}
}
@ -175,23 +186,11 @@ public abstract class BlockEntityAbstractImpetus extends BlockEntity {
}
for (var pos : this.trackedBlocks) {
if (!this.level.getBlockState(pos).is(HexBlocks.WRITTEN_SLATE.get())) {
if (!(this.level.getBlockState(pos).getBlock() instanceof BlockCircleComponent)) {
return Vec3.atBottomCenterOf(pos);
}
}
var blockChecking = this.level.getBlockState(this.nextBlock);
if (!blockChecking.is(HexBlocks.WRITTEN_SLATE.get())) {
BlockPos errorPos;
if (this.trackedBlocks.isEmpty()) {
// then we just activated the circle
errorPos = this.getBlockPos().above();
} else {
errorPos = this.trackedBlocks.get(this.trackedBlocks.size() - 1);
}
return Vec3.atBottomCenterOf(errorPos);
}
if (this.trackedBlocks.size() > HexConfig.maxSpellCircleLength.get()) {
return Vec3.atBottomCenterOf(this.trackedBlocks.get(this.trackedBlocks.size() - 1));
}
@ -225,7 +224,7 @@ public abstract class BlockEntityAbstractImpetus extends BlockEntity {
protected void stopCasting() {
for (var tracked : this.trackedBlocks) {
var bs = this.level.getBlockState(tracked);
this.level.setBlockAndUpdate(tracked, bs.setValue(BlockSlate.LIT, false));
this.level.setBlockAndUpdate(tracked, bs.setValue(BlockCircleComponent.ENERGIZED, false));
}
this.activator = null;
@ -234,7 +233,7 @@ public abstract class BlockEntityAbstractImpetus extends BlockEntity {
this.foundAll = false;
this.level.setBlockAndUpdate(this.getBlockPos(),
this.getBlockState().setValue(BlockAbstractImpetus.LIT, false));
this.getBlockState().setValue(BlockCircleComponent.ENERGIZED, false));
}
@Nullable
@ -270,9 +269,8 @@ public abstract class BlockEntityAbstractImpetus extends BlockEntity {
return scale[note];
}
@Override
protected void saveAdditional(CompoundTag tag) {
protected void saveModData(CompoundTag tag) {
if (this.activator != null && this.colorizer != null && this.nextBlock != null && this.trackedBlocks != null) {
tag.putUUID(TAG_ACTIVATOR, this.activator);
tag.put(TAG_NEXT_BLOCK, NbtUtils.writeBlockPos(this.nextBlock));
@ -289,16 +287,7 @@ public abstract class BlockEntityAbstractImpetus extends BlockEntity {
}
@Override
public CompoundTag getUpdateTag() {
var out = new CompoundTag();
this.saveAdditional(out);
return out;
}
@Override
public void load(CompoundTag tag) {
super.load(tag);
protected void loadModData(CompoundTag tag) {
if (tag.contains(TAG_ACTIVATOR) && tag.contains(TAG_COLORIZER) && tag.contains(TAG_NEXT_BLOCK)
&& tag.contains(TAG_TRACKED_BLOCKS)) {
this.activator = tag.getUUID(TAG_ACTIVATOR);
@ -315,9 +304,6 @@ public abstract class BlockEntityAbstractImpetus extends BlockEntity {
this.mana = tag.getInt(TAG_MANA);
}
private static final Direction[] HORIZONTAL_DIRS = {Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST};
// this is a good use of my time
private static final int[] MAJOR_SCALE = {0, 2, 4, 5, 7, 9, 11, 12};
private static final int[] MINOR_SCALE = {0, 2, 3, 5, 7, 8, 11, 12};

View file

@ -10,7 +10,6 @@ import at.petrak.hexcasting.common.items.HexItems
import at.petrak.hexcasting.common.items.ItemDataHolder
import at.petrak.hexcasting.common.items.ItemScroll
import at.petrak.hexcasting.hexmath.HexPattern
import net.minecraft.world.item.ItemStack
// we make this a spell cause imo it's a little ... anticlimactic for it to just make no noise
object OpWrite : SpellOperator {
@ -35,12 +34,11 @@ object OpWrite : SpellOperator {
handItem.writeDatum(tag, datum)
} else if (handItem == HexItems.SCROLL.get() && !tag.contains(ItemScroll.TAG_PATTERN) && datum.payload is HexPattern) {
tag.put(ItemScroll.TAG_PATTERN, datum.payload.serializeToNBT())
} else if (handItem == HexItems.BLANK_SLATE.get() && datum.payload is HexPattern) {
val newStack = ItemStack(HexItems.WRITTEN_SLATE.get(), handStack.count)
val newTag = tag.copy() // in case you named it or something??
newTag.put(BlockEntitySlate.TAG_PATTERN, datum.payload.serializeToNBT())
newStack.tag = newTag
ctx.caster.setItemInHand(ctx.otherHand, newStack)
} else if (handItem == HexItems.SLATE.get() && datum.payload is HexPattern) {
val bet = tag.getCompound("BlockEntityTag")
bet.put(BlockEntitySlate.TAG_PATTERN, datum.payload.serializeToNBT())
// Just in case it's brand new
tag.put("BlockEntityTag", bet)
} else {
// Fuck
}

View file

@ -10,7 +10,10 @@ import at.petrak.hexcasting.common.items.magic.ItemManaBattery;
import at.petrak.hexcasting.common.items.magic.ItemTrinket;
import net.minecraft.core.NonNullList;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.*;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
@ -95,10 +98,8 @@ public class HexItems {
public static final RegistryObject<ItemAbacus> ABACUS = ITEMS.register("abacus",
() -> new ItemAbacus(unstackable()));
public static final RegistryObject<Item> BLANK_SLATE = ITEMS.register("slate_blank",
() -> new Item(props()));
public static final RegistryObject<BlockItem> WRITTEN_SLATE = ITEMS.register("slate_written",
() -> new BlockItem(HexBlocks.WRITTEN_SLATE.get(), new Item.Properties()));
public static final RegistryObject<ItemSlate> SLATE = ITEMS.register("slate",
() -> new ItemSlate(HexBlocks.SLATE.get(), props()));
// BUFF SANDVICH
public static final RegistryObject<Item> SUBMARINE_SANDWICH = ITEMS.register("sub_sandwich",

View file

@ -0,0 +1,33 @@
package at.petrak.hexcasting.common.items;
import at.petrak.hexcasting.HexMod;
import at.petrak.hexcasting.common.blocks.circles.BlockEntitySlate;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
public class ItemSlate extends BlockItem {
public static final ResourceLocation WRITTEN_PRED = new ResourceLocation(HexMod.MOD_ID, "written");
public ItemSlate(Block pBlock, Properties pProperties) {
super(pBlock, pProperties);
}
@Override
public Component getName(ItemStack pStack) {
var key = HexMod.MOD_ID + ".block.slate." + (hasPattern(pStack) ? "written" : "blank");
return new TranslatableComponent(key);
}
public static boolean hasPattern(ItemStack stack) {
var tag = stack.getTag();
if (tag != null && tag.contains("BlockEntityTag")) {
var bet = tag.getCompound("BlockEntityTag");
return bet.contains(BlockEntitySlate.TAG_PATTERN);
}
return false;
}
}

View file

@ -16,13 +16,13 @@ public class BlockStatesAndModels extends BlockStateProvider {
@Override
protected void registerStatesAndModels() {
simpleBlock(HexBlocks.WRITTEN_SLATE.get(), models().getExistingFile(modLoc("slate")));
simpleBlock(HexBlocks.SLATE.get(), models().getExistingFile(modLoc("slate")));
var slateBlock = models().cubeAll("slate_block", modLoc("block/slate"));
simpleBlock(HexBlocks.SLATE_BLOCK.get(), slateBlock);
simpleBlockItem(HexBlocks.SLATE_BLOCK.get(), slateBlock);
getVariantBuilder(HexBlocks.IMPETUS_RIGHTCLICK.get()).forAllStates(bs -> {
var isLit = bs.getValue(BlockAbstractImpetus.LIT);
var isLit = bs.getValue(BlockAbstractImpetus.ENERGIZED);
var litness = isLit ? "lit" : "dim";
var dir = bs.getValue(BlockAbstractImpetus.FACING);
@ -37,7 +37,7 @@ public class BlockStatesAndModels extends BlockStateProvider {
var name = "impetus_rightclick" + (isLit ? "_lit" : "");
var model = models().cube(name, bottom, top, north, south, east, west)
.texture("particle", bottom);
if (!bs.getValue(BlockAbstractImpetus.LIT) && dir == Direction.SOUTH) {
if (!isLit && dir == Direction.SOUTH) {
simpleBlockItem(HexBlocks.IMPETUS_RIGHTCLICK.get(), model);
}
return ConfiguredModel.builder()

View file

@ -4,6 +4,7 @@ import at.petrak.hexcasting.HexMod;
import at.petrak.hexcasting.common.items.HexItems;
import at.petrak.hexcasting.common.items.ItemFocus;
import at.petrak.hexcasting.common.items.ItemScroll;
import at.petrak.hexcasting.common.items.ItemSlate;
import at.petrak.hexcasting.common.items.magic.ItemManaBattery;
import at.petrak.hexcasting.common.items.magic.ItemPackagedSpell;
import com.mojang.datafixers.util.Pair;
@ -28,9 +29,6 @@ public class ItemModels extends ItemModelProvider {
simpleItem(HexItems.SUBMARINE_SANDWICH.get());
simpleItem(HexItems.SCRYING_LENS.get());
simpleItem(HexItems.ABACUS.get());
simpleItem(HexItems.BLANK_SLATE.get());
simpleItem(HexItems.WRITTEN_SLATE.get());
simpleItem(modLoc("scroll_pristine"));
simpleItem(modLoc("scroll_ancient"));
@ -116,6 +114,17 @@ public class ItemModels extends ItemModelProvider {
}
singleTexture(HexItems.UUID_COLORIZER.getId().getPath(), new ResourceLocation("item/generated"),
"layer0", new ResourceLocation(HexMod.MOD_ID, "item/colorizer/uuid"));
simpleItem(modLoc("slate_blank"));
simpleItem(modLoc("slate_written"));
getBuilder(HexItems.SLATE.getId().getPath()).override()
.predicate(ItemSlate.WRITTEN_PRED, 0)
.model(new ModelFile.UncheckedModelFile(modLoc("item/slate_blank")))
.end()
.override()
.predicate(ItemSlate.WRITTEN_PRED, 1)
.model(new ModelFile.UncheckedModelFile(modLoc("item/slate_written")))
.end();
}
public void simpleItem(Item item) {

View file

@ -48,8 +48,8 @@
"item.hexcasting.pride_colorizer_13": "Aroace Pigment",
"item.hexcasting.uuid_colorizer": "Soulglimmer Pigment",
"block.hexcasting.conjured": "Conjured Block",
"block.hexcasting.slate_blank": "Blank Slate",
"block.hexcasting.slate_written": "Patterned Slate",
"hexcasting.block.slate.blank": "Blank Slate",
"hexcasting.block.slate.written": "Patterned Slate",
"itemGroup.hexcasting": "Hexcasting",
"hexcasting.tooltip.spellbook.page": "§7Selected Page §a§l%d§7/§a§l%d§r",