i need to go to sleep
This commit is contained in:
parent
4e3d3076a2
commit
2464d9b748
7 changed files with 86 additions and 44 deletions
|
@ -1,12 +1,13 @@
|
|||
package at.petrak.hexcasting.api.misc;
|
||||
|
||||
import at.petrak.hexcasting.api.addldata.Colorizer;
|
||||
import at.petrak.hexcasting.api.mod.HexApiItems;
|
||||
import at.petrak.hexcasting.api.utils.HexUtils;
|
||||
import at.petrak.hexcasting.common.lib.HexItems;
|
||||
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.FastColor;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
|
@ -26,7 +27,7 @@ public record FrozenColorizer(ItemStack item, UUID owner) {
|
|||
public static final String TAG_OWNER = "owner";
|
||||
|
||||
public static final Supplier<FrozenColorizer> DEFAULT =
|
||||
() -> new FrozenColorizer(new ItemStack(HexApiItems.COLORIZER_WHITE), Util.NIL_UUID);
|
||||
() -> new FrozenColorizer(new ItemStack(HexItems.DYE_COLORIZERS.get(DyeColor.WHITE)), Util.NIL_UUID);
|
||||
|
||||
public CompoundTag serialize() {
|
||||
var out = new CompoundTag();
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
package at.petrak.hexcasting.common.entities;
|
||||
|
||||
import at.petrak.hexcasting.client.RenderLib;
|
||||
import at.petrak.hexcasting.common.lib.HexItems;
|
||||
import at.petrak.hexcasting.common.items.ItemScroll;
|
||||
import at.petrak.hexcasting.common.lib.HexSounds;
|
||||
import at.petrak.hexcasting.annotations.SoftImplement;
|
||||
import at.petrak.hexcasting.api.spell.math.HexPattern;
|
||||
import at.petrak.hexcasting.api.utils.HexUtils;
|
||||
import at.petrak.hexcasting.client.RenderLib;
|
||||
import at.petrak.hexcasting.common.items.ItemScroll;
|
||||
import at.petrak.hexcasting.common.lib.HexItems;
|
||||
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.Tag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
|
@ -28,13 +30,11 @@ import net.minecraft.world.level.Level;
|
|||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.entity.IEntityAdditionalSpawnData;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EntityWallScroll extends HangingEntity implements IEntityAdditionalSpawnData {
|
||||
public class EntityWallScroll extends HangingEntity {
|
||||
private static final EntityDataAccessor<Boolean> SHOWS_STROKE_ORDER = SynchedEntityData.defineId(
|
||||
EntityWallScroll.class,
|
||||
EntityDataSerializers.BOOLEAN);
|
||||
|
@ -50,7 +50,7 @@ public class EntityWallScroll extends HangingEntity implements IEntityAdditional
|
|||
}
|
||||
|
||||
public EntityWallScroll(Level world, BlockPos pos, Direction dir, ItemStack scroll) {
|
||||
super(HexEntities.WALL_SCROLL.get(), world, pos);
|
||||
super(HexEntities.WALL_SCROLL, world, pos);
|
||||
this.loadDataFromScrollItem(scroll);
|
||||
this.setDirection(dir);
|
||||
}
|
||||
|
@ -116,13 +116,13 @@ public class EntityWallScroll extends HangingEntity implements IEntityAdditional
|
|||
@Override
|
||||
public InteractionResult interactAt(Player pPlayer, Vec3 pVec, InteractionHand pHand) {
|
||||
var handStack = pPlayer.getItemInHand(pHand);
|
||||
if (handStack.is(HexItems.AMETHYST_DUST.get()) && !this.getShowsStrokeOrder()) {
|
||||
if (handStack.is(HexItems.AMETHYST_DUST) && !this.getShowsStrokeOrder()) {
|
||||
if (!pPlayer.getAbilities().instabuild) {
|
||||
handStack.shrink(1);
|
||||
}
|
||||
this.setShowsStrokeOrder(true);
|
||||
|
||||
pPlayer.level.playSound(pPlayer, this, HexSounds.SCROLL_DUST.get(), SoundSource.PLAYERS, 1f, 1f);
|
||||
pPlayer.level.playSound(pPlayer, this, HexSounds.SCROLL_DUST, SoundSource.PLAYERS, 1f, 1f);
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
return super.interactAt(pPlayer, pVec, pHand);
|
||||
|
@ -135,9 +135,10 @@ public class EntityWallScroll extends HangingEntity implements IEntityAdditional
|
|||
|
||||
@Override
|
||||
public Packet<?> getAddEntityPacket() {
|
||||
return NetworkHooks.getEntitySpawningPacket(this);
|
||||
return new ClientboundAddEntityPacket(this);
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void writeSpawnData(FriendlyByteBuf buf) {
|
||||
buf.writeVarInt(this.direction.ordinal());
|
||||
|
@ -154,11 +155,12 @@ public class EntityWallScroll extends HangingEntity implements IEntityAdditional
|
|||
this.loadDataFromScrollItem(scroll);
|
||||
this.setDirection(this.direction);
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void addAdditionalSaveData(CompoundTag tag) {
|
||||
tag.putByte("direction", (byte) this.direction.ordinal());
|
||||
tag.put("scroll", this.scroll.serializeNBT());
|
||||
tag.put("scroll", HexUtils.serialize(this.scroll));
|
||||
tag.putBoolean("showsStrokeOrder", this.getShowsStrokeOrder());
|
||||
super.addAdditionalSaveData(tag);
|
||||
}
|
||||
|
@ -186,7 +188,8 @@ public class EntityWallScroll extends HangingEntity implements IEntityAdditional
|
|||
this.setPos(blockpos.getX(), blockpos.getY(), blockpos.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
// todo: fabric
|
||||
@SoftImplement("forge")
|
||||
public ItemStack getPickedResult(HitResult target) {
|
||||
return this.scroll.copy();
|
||||
}
|
||||
|
|
|
@ -1,18 +1,35 @@
|
|||
package at.petrak.hexcasting.common.entities;
|
||||
|
||||
import at.petrak.hexcasting.HexMod;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||
|
||||
public class HexEntities {
|
||||
public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES,
|
||||
HexMod.MOD_ID);
|
||||
public static void registerEntities(BiConsumer<EntityType<?>, ResourceLocation> r) {
|
||||
for (var e : ENTITIES.entrySet()) {
|
||||
r.accept(e.getValue(), e.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
public static final RegistryObject<EntityType<EntityWallScroll>> WALL_SCROLL = ENTITIES.register("wall_scroll",
|
||||
() -> EntityType.Builder.<EntityWallScroll>of(EntityWallScroll::new, MobCategory.MISC)
|
||||
private static final Map<ResourceLocation, EntityType<?>> ENTITIES = new LinkedHashMap<>();
|
||||
|
||||
public static final EntityType<EntityWallScroll> WALL_SCROLL = register("wall_scroll",
|
||||
EntityType.Builder.<EntityWallScroll>of(EntityWallScroll::new, MobCategory.MISC)
|
||||
.sized(0.5f, 0.5f).clientTrackingRange(10).updateInterval(Integer.MAX_VALUE)
|
||||
.build("wall_scroll"));
|
||||
|
||||
private static <T extends Entity> EntityType<T> register(String id, EntityType<T> type) {
|
||||
var old = ENTITIES.put(modLoc(id), type);
|
||||
if (old != null) {
|
||||
throw new IllegalArgumentException("Typo? Duplicate id " + id);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ import net.minecraft.world.item.crafting.RecipeType;
|
|||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.registries.ForgeRegistryEntry;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
// God I am a horrible person
|
||||
|
@ -26,8 +25,6 @@ public record BrainsweepRecipe(
|
|||
VillagerIngredient villagerIn,
|
||||
BlockState result
|
||||
) implements Recipe<Container> {
|
||||
|
||||
|
||||
public boolean matches(BlockState blockIn, Villager villagerIn) {
|
||||
return this.blockIn.test(blockIn) && this.villagerIn.test(villagerIn);
|
||||
}
|
||||
|
@ -44,7 +41,7 @@ public record BrainsweepRecipe(
|
|||
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return HexRecipeSerializers.BRAINSWEEP.get();
|
||||
return HexRecipeSerializers.BRAINSWEEP;
|
||||
}
|
||||
|
||||
// in order to get this to be a "Recipe" we need to do a lot of bending-over-backwards
|
||||
|
@ -69,7 +66,7 @@ public record BrainsweepRecipe(
|
|||
return ItemStack.EMPTY.copy();
|
||||
}
|
||||
|
||||
public static class Serializer extends ForgeRegistryEntry<RecipeSerializer<?>> implements RecipeSerializer<BrainsweepRecipe> {
|
||||
public static class Serializer implements RecipeSerializer<BrainsweepRecipe> {
|
||||
@Override
|
||||
public BrainsweepRecipe fromJson(ResourceLocation recipeID, JsonObject json) {
|
||||
var blockIn = StateIngredientHelper.deserialize(GsonHelper.getAsJsonObject(json, "blockIn"));
|
||||
|
|
|
@ -1,26 +1,39 @@
|
|||
package at.petrak.hexcasting.common.recipe;
|
||||
|
||||
import at.petrak.hexcasting.HexMod;
|
||||
import net.minecraft.world.item.Item;
|
||||
import at.petrak.hexcasting.api.HexAPI;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||
|
||||
public class HexRecipeSerializers {
|
||||
public static final DeferredRegister<RecipeSerializer<?>> SERIALIZERS = DeferredRegister.create(
|
||||
ForgeRegistries.RECIPE_SERIALIZERS, HexMod.MOD_ID);
|
||||
public void register(BiConsumer<ResourceLocation, RecipeSerializer<?>> r) {
|
||||
for (var e : SERIALIZERS.entrySet()) {
|
||||
r.accept(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static final RegistryObject<RecipeSerializer<?>> BRAINSWEEP = SERIALIZERS.register("brainsweep",
|
||||
BrainsweepRecipe.Serializer::new);
|
||||
private static final Map<ResourceLocation, RecipeSerializer<?>> SERIALIZERS = new LinkedHashMap<>();
|
||||
public static final RecipeSerializer<?> BRAINSWEEP = register("brainsweep",
|
||||
new BrainsweepRecipe.Serializer());
|
||||
public static RecipeType<BrainsweepRecipe> BRAINSWEEP_TYPE;
|
||||
|
||||
private static <T extends Recipe<?>> RecipeSerializer<T> register(String name, RecipeSerializer<T> rs) {
|
||||
var old = SERIALIZERS.put(modLoc(name), rs);
|
||||
if (old != null) {
|
||||
throw new IllegalArgumentException("Typo? Duplicate id " + name);
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
// Like in the statistics, gotta register it at some point
|
||||
@SubscribeEvent
|
||||
public static void registerTypes(RegistryEvent.Register<Item> evt) {
|
||||
BRAINSWEEP_TYPE = RecipeType.register(HexMod.MOD_ID + ":brainsweep");
|
||||
public static void registerTypes() {
|
||||
BRAINSWEEP_TYPE = RecipeType.register(HexAPI.MOD_ID + ":brainsweep");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,10 @@ import at.petrak.hexcasting.common.blocks.behavior.HexStrippables
|
|||
import at.petrak.hexcasting.common.casting.RegisterPatterns
|
||||
import at.petrak.hexcasting.common.casting.operators.spells.great.OpFlight
|
||||
import at.petrak.hexcasting.common.command.PatternResLocArgument
|
||||
import at.petrak.hexcasting.common.entities.HexEntities
|
||||
import at.petrak.hexcasting.common.lib.*
|
||||
import at.petrak.hexcasting.common.misc.Brainsweeping
|
||||
import at.petrak.hexcasting.common.recipe.HexRecipeSerializers
|
||||
import at.petrak.hexcasting.forge.ForgeHexConfig
|
||||
import at.petrak.hexcasting.forge.ForgeOnlyEvents
|
||||
import at.petrak.hexcasting.forge.cap.CapSyncers
|
||||
|
@ -18,6 +20,7 @@ import at.petrak.hexcasting.forge.network.ForgePacketHandler
|
|||
import net.minecraft.commands.synchronization.ArgumentTypes
|
||||
import net.minecraft.commands.synchronization.EmptyArgumentSerializer
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraftforge.common.ForgeConfigSpec
|
||||
import net.minecraftforge.event.RegistryEvent
|
||||
import net.minecraftforge.event.entity.living.LivingConversionEvent
|
||||
|
@ -76,6 +79,8 @@ object ForgeHexInitializer {
|
|||
bind(ForgeRegistries.BLOCK_ENTITIES, HexBlockEntities::registerTiles)
|
||||
bind(ForgeRegistries.ITEMS, HexItems::registerItems)
|
||||
|
||||
bind(ForgeRegistries.ENTITIES, HexEntities::registerEntities)
|
||||
|
||||
bind(ForgeRegistries.PARTICLE_TYPES, HexParticles::registerParticles)
|
||||
}
|
||||
|
||||
|
@ -95,6 +100,12 @@ object ForgeHexInitializer {
|
|||
}
|
||||
}
|
||||
|
||||
// We have to do these at some point when the registries are still open
|
||||
modBus.addListener { _: RegistryEvent<Item> ->
|
||||
HexRecipeSerializers.registerTypes()
|
||||
// TODO statistics
|
||||
}
|
||||
|
||||
modBus.addListener { _: FMLLoadCompleteEvent ->
|
||||
getLogger().info(
|
||||
PatternRegistry.getPatternCountInfo()
|
||||
|
|
|
@ -84,7 +84,7 @@ public class BrainsweepRecipeBuilder implements RecipeBuilder {
|
|||
|
||||
@Override
|
||||
public RecipeSerializer<?> getType() {
|
||||
return HexRecipeSerializers.BRAINSWEEP.get();
|
||||
return HexRecipeSerializers.BRAINSWEEP;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
Loading…
Reference in a new issue