Skip to content

Commit

Permalink
Port to 1.18.2, fix wisp only targeting line of sight, some bugs stil…
Browse files Browse the repository at this point in the history
…l present
  • Loading branch information
itsmeow committed Apr 19, 2022
1 parent 0e34ac8 commit 68a9c6f
Show file tree
Hide file tree
Showing 20 changed files with 82 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public PushReaction getPistonPushReaction(BlockState state) {
@Override
public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor worldIn, BlockPos currentPos, BlockPos facingPos) {
if(stateIn.getValue(WATERLOGGED)) {
worldIn.getLiquidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(worldIn));
worldIn.scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(worldIn));
}

return stateIn.getValue(FACING) == facing && !stateIn.canSurvive(worldIn, currentPos) ? Blocks.AIR.defaultBlockState() : super.updateShape(stateIn, facing, facingState, worldIn, currentPos, facingPos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import com.mojang.math.Vector3f;
import dev.architectury.extensions.BlockEntityExtension;
import dev.architectury.registry.registries.Registries;
import dev.architectury.utils.NbtType;
import dev.itsmeow.whisperwoods.WhisperwoodsMod;
import dev.itsmeow.whisperwoods.block.GhostLightBlock;
import dev.itsmeow.whisperwoods.block.HandOfFateBlock;
Expand All @@ -25,6 +23,10 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerLevel;
Expand Down Expand Up @@ -55,9 +57,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public class HandOfFateBlockEntity extends BlockEntity implements BlockEntityExtension {
public class HandOfFateBlockEntity extends BlockEntity {

public static final ImmutableBiMap<String, HOFRecipe> RECIPES = ImmutableBiMap.of(
"hirschgeist", new HOFRecipe(ChatFormatting.AQUA, true, Items.BONE, Items.DIAMOND, Items.SOUL_SAND),
Expand All @@ -82,8 +83,13 @@ public Item getDisplayItem() {
@Override
public void setChanged() {
super.setChanged();
if (this.hasLevel() && !this.level.isClientSide())
this.syncData();
this.sync();
}

public void sync() {
if (level != null && !level.isClientSide()) {
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
}
}

public boolean isLit() {
Expand Down Expand Up @@ -111,7 +117,7 @@ protected void playSound(SoundEvent sound, float vol, float pitch) {

protected void sendToTrackers(HOFEffectPacket pkt) {
if (this.hasLevel()) {
WWNetwork.HANDLER.sendToPlayers(((ServerChunkCache) this.getLevel().getChunkSource()).chunkMap.getPlayers(new ChunkPos(worldPosition), false).collect(Collectors.toSet()), pkt);
WWNetwork.HANDLER.sendToPlayers(((ServerChunkCache) this.getLevel().getChunkSource()).chunkMap.getPlayers(new ChunkPos(worldPosition), false), pkt);
}
}

Expand Down Expand Up @@ -206,7 +212,7 @@ public void onRecipeComplete(HOFRecipe recipe, BlockState state, Level worldIn,
wColor = WispColors.values()[wisp.getRandom().nextInt(WispColors.values().length)];
}
wisp.setPos((double) pos.getX() + 0.5D, (double) pos.getY() + 1D, (double) pos.getZ() + 0.5D);
double d0 = 1.0D + Shapes.collide(Direction.Axis.Y, wisp.getBoundingBox(), world.getCollisions(null, new AABB(pos), e -> true), -1.0D);
double d0 = 1.0D + Shapes.collide(Direction.Axis.Y, wisp.getBoundingBox(), world.getCollisions(null, new AABB(pos)), -1.0D);
wisp.moveTo((double) pos.getX() + 0.5D, (double) pos.getY() + d0, (double) pos.getZ() + 0.5D, Mth.wrapDegrees(world.random.nextFloat() * 360.0F), 0.0F);
wisp.yHeadRot = wisp.getYRot();
wisp.yBodyRot = wisp.getYRot();
Expand All @@ -233,27 +239,28 @@ public void onRecipeComplete(HOFRecipe recipe, BlockState state, Level worldIn,
}

@Override
public void load(CompoundTag compoundTag) {
super.load(compoundTag);
this.getRecipeContainer().read(compoundTag);
this.displayDirty = true;
public Packet<ClientGamePacketListener> getUpdatePacket() {
return ClientboundBlockEntityDataPacket.create(this);
}

@Override
public CompoundTag save(CompoundTag compound) {
CompoundTag c = super.save(compound);
this.getRecipeContainer().write(compound);
return c;
public CompoundTag getUpdateTag() {
CompoundTag nbt = super.getUpdateTag();
saveAdditional(nbt);
return nbt;
}

@Override
public void loadClientData(BlockState pos, CompoundTag tag) {
this.load(tag);
public void load(CompoundTag compoundTag) {
super.load(compoundTag);
this.getRecipeContainer().read(compoundTag);
this.displayDirty = true;
}

@Override
public CompoundTag saveClientData(CompoundTag tag) {
return this.save(tag);
public void saveAdditional(CompoundTag compound) {
super.saveAdditional(compound);
this.getRecipeContainer().write(compound);
}

public void dropItems(Level worldIn, BlockPos pos) {
Expand Down Expand Up @@ -392,7 +399,7 @@ public boolean hasItem(Item item) {

public void read(CompoundTag nbt) {
if (nbt.contains("items")) {
nbt.getList("items", NbtType.STRING).forEach(i -> data.put(i.getAsString(), true));
nbt.getList("items", Tag.TAG_STRING).forEach(i -> data.put(i.getAsString(), true));
} else {
data.keySet().forEach((i) -> data.put(i, false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ public EntityTypeContainer<EntityHidebehind> getContainer() {

@Override
public String[] getTypesFor(ResourceKey<Biome> biomeKey, Biome biome, Set<BiomeTypes.Type> types, MobSpawnType reason) {
if(biomeKey == Biomes.GIANT_SPRUCE_TAIGA || biomeKey == Biomes.GIANT_SPRUCE_TAIGA_HILLS || biomeKey == Biomes.GIANT_TREE_TAIGA || biomeKey == Biomes.GIANT_TREE_TAIGA_HILLS) {
if(biomeKey == Biomes.OLD_GROWTH_SPRUCE_TAIGA || biomeKey == Biomes.OLD_GROWTH_SPRUCE_TAIGA) {
return new String[] { "mega_taiga", "mega_taiga", "mega_taiga", "darkforest" };
}
if(types.contains(BiomeTypes.CONIFEROUS)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected void customServerAiStep() {
this.setNotLanded();
}
}
if(this.targetPosition == null || this.random.nextInt(30) == 0 || (this.targetPosition.closerThan(this.position(), 1.0D) && !isLightBlock(level.getBlockState(this.targetPosition)))) {
if(this.targetPosition == null || this.random.nextInt(30) == 0 || (this.targetPosition.closerThan(this.blockPosition(), 1.0D) && !isLightBlock(level.getBlockState(this.targetPosition)))) {
int i = 12;
int j = 2;
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
Expand Down Expand Up @@ -189,7 +189,7 @@ protected void customServerAiStep() {
Vec3 vec3d1 = vec3d.add((Math.signum(d0) * 0.5D - vec3d.x) * (double) 0.1F, (Math.signum(d1) * (double) 0.7F - vec3d.y) * (double) 0.1F, (Math.signum(d2) * 0.5D - vec3d.z) * (double) 0.1F);
float width = this.getContainer().getEntityType().getDimensions().width * 0.8F;
AABB axisalignedbb = AABB.ofSize(vec3d1.add(this.position()), width, 0.1F, width);
boolean collides = this.level.getBlockCollisions(this, axisalignedbb, (state, pos2) -> state.isSuffocating(this.level, pos2)).findAny().isPresent();
boolean collides = this.level.getBlockCollisions(this, axisalignedbb).iterator().hasNext();
if(collides) {
vec3d1 = vec3d1.multiply(0.5, 0.5, 0.5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class EntityWisp extends Animal implements IContainerEntity<EntityWisp> {
public static final EntityDataAccessor<Float> PASSIVE_SCALE = SynchedEntityData.defineId(EntityWisp.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Integer> COLOR_VARIANT = SynchedEntityData.defineId(EntityWisp.class, EntityDataSerializers.INT);
private static final TargetingConditions PASSIVE_SCALE_PREDICATE = TargetingConditions.forNonCombat().ignoreInvisibilityTesting().ignoreLineOfSight();
private static final TargetingConditions HOSTILE_TARGET_PREDICATE = TargetingConditions.forCombat().selector(e -> !(e.getItemBySlot(EquipmentSlot.HEAD).getItem() instanceof ItemBlockHirschgeistSkull));
private static final TargetingConditions HOSTILE_TARGET_PREDICATE = TargetingConditions.forCombat().ignoreLineOfSight().selector(e -> !(e.getItemBySlot(EquipmentSlot.HEAD).getItem() instanceof ItemBlockHirschgeistSkull));
protected ResourceLocation targetTexture;
private boolean shouldBeHostile = false;
private int attackCooldown = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
import dev.itsmeow.whisperwoods.init.ModEntities;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.Mth;
Expand All @@ -36,7 +33,6 @@
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.VoxelShape;

import java.util.EnumSet;
import java.util.Random;
Expand Down Expand Up @@ -109,7 +105,7 @@ protected SoundEvent getDeathSound() {

@SuppressWarnings("deprecation")
public static boolean canSpawn(EntityType<EntityZotzpyre> type, LevelAccessor world, MobSpawnType reason, BlockPos pos, Random rand) {
if (pos.getY() >= world.getSeaLevel() && !BiomeTypes.getTypes(ResourceKey.create(Registry.BIOME_REGISTRY, ((ServerLevel)world).getServer().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getKey(world.getBiome(pos)))).contains(BiomeTypes.JUNGLE)) {
if (pos.getY() >= world.getSeaLevel() && !BiomeTypes.getTypes(world.getBiome(pos).unwrapKey().get()).contains(BiomeTypes.JUNGLE)) {
return false;
} else {
return checkAnyLightMonsterSpawnRules(type, world, reason, pos, rand);
Expand Down Expand Up @@ -399,7 +395,7 @@ private boolean canReach(Vec3 vec3, int i) {
AABB box = this.mob.getBoundingBox();
for (int j = 1; j < i; ++j) {
box = box.move(vec3);
if (!this.mob.level.getBlockCollisions(this.mob, box).allMatch(VoxelShape::isEmpty)) {
if (this.mob.level.getBlockCollisions(this.mob, box).iterator().hasNext()) {
return false;
}
}
Expand Down
20 changes: 10 additions & 10 deletions common/src/main/java/dev/itsmeow/whisperwoods/init/ModTags.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
package dev.itsmeow.whisperwoods.init;

import dev.architectury.hooks.tags.TagHooks;
import dev.itsmeow.whisperwoods.WhisperwoodsMod;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;

public class ModTags {

public static final class Blocks {
public static final Tag.Named<Block> GHOST_LIGHT = tag("ghost_light");
public static final Tag.Named<Block> WISP_LANTERN = tag("wisp_lantern");
public static final TagKey<Block> GHOST_LIGHT = tag("ghost_light");
public static final TagKey<Block> WISP_LANTERN = tag("wisp_lantern");


public static void loadTags() {
// This is a classloading dummy.
}

private static Tag.Named<Block> tag(String name) {
return TagHooks.optionalBlock(new ResourceLocation(WhisperwoodsMod.MODID, name));
private static TagKey<Block> tag(String name) {
return TagKey.create(Registry.BLOCK_REGISTRY, new ResourceLocation(WhisperwoodsMod.MODID, name));
}
}

public static final class Items {
public static final Tag.Named<Item> GHOST_LIGHT = tag("ghost_light");
public static final Tag.Named<Item> WISP_LANTERN = tag("wisp_lantern");
public static final TagKey<Item> GHOST_LIGHT = tag("ghost_light");
public static final TagKey<Item> WISP_LANTERN = tag("wisp_lantern");

public static void loadTags() {
// This is a classloading dummy.
}

private static Tag.Named<Item> tag(String name) {
return TagHooks.optionalItem(new ResourceLocation(WhisperwoodsMod.MODID, name));
private static TagKey<Item> tag(String name) {
return TagKey.create(Registry.ITEM_REGISTRY, new ResourceLocation(WhisperwoodsMod.MODID, name));
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package dev.itsmeow.whisperwoods.util;

import dev.itsmeow.imdlib.entity.interfaces.IContainerEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.Shapes;

public interface IOverrideCollisions<T extends Mob> extends IContainerEntity<T> {

default boolean insideOpaque() {
if (this.getImplementation().noPhysics) {
return false;
} else {
float f1 = this.getImplementation().getType().getDimensions().width * 0.8F;
AABB axisalignedbb = AABB.ofSize(this.getImplementation().getEyePosition(), f1, 0.1F, f1);
return this.getImplementation().getCommandSenderWorld().getBlockCollisions(this.getImplementation(), axisalignedbb, (state, pos) -> state.isSuffocating(this.getImplementation().getCommandSenderWorld(), pos) && !preventSuffocation(state)).findAny().isPresent();
float f = this.getImplementation().getType().getDimensions().width * 0.8F;
AABB aABB = AABB.ofSize(this.getImplementation().getEyePosition(), (double)f, 1.0E-6D, (double)f);
return BlockPos.betweenClosedStream(aABB).anyMatch((blockPos) -> {
BlockState blockState = this.getImplementation().getLevel().getBlockState(blockPos);
return !blockState.isAir() && blockState.isSuffocating(this.getImplementation().getLevel(), blockPos) && !preventSuffocation(blockState) && Shapes.joinIsNotEmpty(blockState.getCollisionShape(this.getImplementation().getLevel(), blockPos).move(blockPos.getX(), blockPos.getY(), blockPos.getZ()), Shapes.create(aABB), BooleanOp.AND);
});
}
}

Expand Down
6 changes: 2 additions & 4 deletions common/src/main/resources/whisperwoods.mixins.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"required": true,
"package": "dev.itsmeow.whisperwoods.mixin",
"compatibilityLevel": "JAVA_16",
"compatibilityLevel": "JAVA_17",
"minVersion": "0.8",
"mixins": [
"EntityMixin",
"LivingEntityMixin",
"GroundPathNavigationMixin"
"LivingEntityMixin"
],
"client": [
"LayerDefinitionsMixin"
Expand Down
Loading

0 comments on commit 68a9c6f

Please sign in to comment.