Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more easy porting stuff #5110

Merged
merged 5 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.*;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
Expand Down Expand Up @@ -53,7 +54,8 @@ public BackpackItem(@Nullable ZetaModule module) {
new Item.Properties()
.stacksTo(1)
.durability(0)
.rarity(Rarity.RARE));
.rarity(Rarity.RARE)
.attributes(createAttributes()));

this.module = module;

Expand Down Expand Up @@ -224,9 +226,8 @@ public ICapabilityProvider initCapabilities(ItemStack stack, CompoundTag oldCapN
return handler;
}

@Override
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot p_40390_) {
return ImmutableMultimap.of();
public static ItemAttributeModifiers createAttributes(){
return ItemAttributeModifiers.builder().build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.material.FluidState;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.neoforged.neoforge.common.util.FakePlayer;
import net.neoforged.neoforge.common.util.FakePlayerFactory;
import org.violetmoon.quark.addons.oddities.module.MagnetsModule;
import org.violetmoon.quark.api.IMagnetMoveAction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
package org.violetmoon.quark.api;

import net.minecraft.world.entity.player.Player;
import net.minecraftforge.items.IItemHandler;
import net.neoforged.neoforge.items.IItemHandler;

import java.util.function.Supplier;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.violetmoon.quark.content.building.block;

import it.unimi.dsi.fastutil.floats.Float2ObjectArrayMap;

import it.unimi.dsi.fastutil.doubles.Double2ObjectArrayMap;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.ExperienceOrb;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.WaterAnimal;
import net.minecraft.world.entity.item.ItemEntity;
Expand All @@ -33,10 +35,8 @@
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.event.ForgeEventFactory;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import org.violetmoon.quark.api.ICrawlSpaceBlock;
import org.violetmoon.zeta.block.SimpleFluidloggedBlock;
import org.violetmoon.zeta.block.ZetaBlock;
Expand All @@ -45,7 +45,7 @@

public class GrateBlock extends ZetaBlock implements SimpleFluidloggedBlock, ICrawlSpaceBlock {
private static final VoxelShape TRUE_SHAPE = box(0, 15, 0, 16, 16, 16);
private static final Float2ObjectArrayMap<VoxelShape> WALK_BLOCK_CACHE = new Float2ObjectArrayMap<>();
private static final Double2ObjectArrayMap<VoxelShape> WALK_BLOCK_CACHE = new Double2ObjectArrayMap<>();

public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final BooleanProperty LAVALOGGED = BooleanProperty.create("lavalogged");
Expand Down Expand Up @@ -97,7 +97,7 @@ public VoxelShape getShape(@NotNull BlockState state, @NotNull BlockGetter world
return TRUE_SHAPE;
}

private static VoxelShape getCachedShape(float stepHeight) {
private static VoxelShape getCachedShape(double stepHeight) {
return WALK_BLOCK_CACHE.computeIfAbsent(stepHeight, GrateBlock::createNewBox);
}

Expand Down Expand Up @@ -125,8 +125,12 @@ public VoxelShape getCollisionShape(@NotNull BlockState state, @NotNull BlockGet
boolean onGrate = world.getBlockState(entity.blockPosition().offset(0, -1, 0)).getBlock() instanceof GrateBlock;

if(preventedType && !leashed && !onGrate) {
return getCachedShape(entity.getStepHeight());
}
LivingEntity livingEntity = (LivingEntity) entity;
AttributeInstance stepHeight = livingEntity.getAttribute(Attributes.STEP_HEIGHT);
if (stepHeight != null) {
return getCachedShape(stepHeight.getValue());
}
}

return TRUE_SHAPE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.syncher.EntityDataAccessor;
Expand Down Expand Up @@ -35,14 +36,15 @@
import net.minecraftforge.entity.IEntityAdditionalSpawnData;
import net.minecraftforge.network.NetworkHooks;

import net.neoforged.neoforge.entity.IEntityWithComplexSpawn;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import org.violetmoon.quark.content.building.module.GlassItemFrameModule;

import java.util.UUID;

public class GlassItemFrame extends ItemFrame implements IEntityAdditionalSpawnData {
public class GlassItemFrame extends ItemFrame implements IEntityWithComplexSpawn {

public static final EntityDataAccessor<Boolean> IS_SHINY = SynchedEntityData.defineId(GlassItemFrame.class, EntityDataSerializers.BOOLEAN);

Expand Down Expand Up @@ -173,10 +175,10 @@ else if(absDiff >= 135 && absDiff < 225)
}

@Override
protected void defineSynchedData() {
super.defineSynchedData();
protected void defineSynchedData(SynchedEntityData.Builder builder) {
super.defineSynchedData(builder);

entityData.define(IS_SHINY, false);
builder.define(IS_SHINY, false);
}

@Override
Expand Down Expand Up @@ -246,14 +248,14 @@ public Packet<ClientGamePacketListener> getAddEntityPacket() {
}

@Override
public void writeSpawnData(FriendlyByteBuf buffer) {
buffer.writeBlockPos(this.pos);
buffer.writeVarInt(this.direction.get3DDataValue());
public void writeSpawnData(RegistryFriendlyByteBuf registryFriendlyByteBuf) {
registryFriendlyByteBuf.writeBlockPos(this.pos);
registryFriendlyByteBuf.writeVarInt(this.direction.get3DDataValue());
}

@Override
public void readSpawnData(FriendlyByteBuf buffer) {
this.pos = buffer.readBlockPos();
this.setDirection(Direction.from3DDataValue(buffer.readVarInt()));
public void readSpawnData(RegistryFriendlyByteBuf registryFriendlyByteBuf) {
this.pos = registryFriendlyByteBuf.readBlockPos();
this.setDirection(Direction.from3DDataValue(registryFriendlyByteBuf.readVarInt()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import net.minecraft.client.player.Input;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;

import org.violetmoon.quark.base.QuarkClient;
Expand Down Expand Up @@ -93,17 +95,20 @@ private void acceptInput() {
if(shouldAccept) {
shouldAccept = false;
Player player = mc.player;
float height = player.getStepHeight();
AttributeInstance stepHeight = player.getAttribute(Attributes.STEP_HEIGHT);
if(stepHeight != null){
double height = stepHeight.getValue();

autorunning = !autorunning;
autorunning = !autorunning;

if(autorunning) {
hadAutoJump = opt.get();
if(autorunning) {
hadAutoJump = opt.get();

if(height < 1)
opt.set(true);
} else
opt.set(hadAutoJump);
if(height < 1)
opt.set(true);
} else
opt.set(hadAutoJump);
}
}
} else
shouldAccept = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ private static Multimap<Attribute, AttributeModifier> getModifiers(ItemStack sta
var map = capturedModifiers.get(slot);
if(slot == AttributeSlot.MAINHAND) {
if(!map.containsKey(Attributes.ATTACK_DAMAGE) && (map.containsKey(Attributes.ATTACK_SPEED) || EnchantmentHelper.getDamageBonus(stack, MobType.UNDEFINED) > 0))
map.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(Util.NIL_UUID, "-", 0, AttributeModifier.Operation.ADDITION));
map.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(Util.NIL_UUID, "-", 0, AttributeModifier.Operation.ADD_VALUE));

if(!map.containsKey(Attributes.ATTACK_SPEED) && map.containsKey(Attributes.ATTACK_DAMAGE))
map.put(Attributes.ATTACK_SPEED, new AttributeModifier(Util.NIL_UUID, "-", 0, AttributeModifier.Operation.ADDITION));
map.put(Attributes.ATTACK_SPEED, new AttributeModifier(Util.NIL_UUID, "-", 0, AttributeModifier.Operation.ADD_VALUE));

if(!map.containsKey(Attributes.ATTACK_KNOCKBACK) && Quark.ZETA.itemExtensions.get(stack).getEnchantmentLevelZeta(stack, Enchantments.KNOCKBACK) > 0)
map.put(Attributes.ATTACK_KNOCKBACK, new AttributeModifier(Util.NIL_UUID, "-", 0, AttributeModifier.Operation.ADDITION));
map.put(Attributes.ATTACK_KNOCKBACK, new AttributeModifier(Util.NIL_UUID, "-", 0, AttributeModifier.Operation.ADD_VALUE));
}
return map;
}
Expand Down Expand Up @@ -300,19 +300,19 @@ private static double getAttribute(Player player, AttributeSlot slot, ItemStack
}

for(AttributeModifier modifier : collection) {
if(modifier.getOperation() == AttributeModifier.Operation.ADDITION)
if(modifier.getOperation() == AttributeModifier.Operation.ADD_VALUE)
value += modifier.getAmount();
}

double rawValue = value;

for(AttributeModifier modifier : collection) {
if(modifier.getOperation() == AttributeModifier.Operation.MULTIPLY_BASE)
if(modifier.getOperation() == AttributeModifier.Operation.ADD_MULTIPLIED_BASE)
value += rawValue * modifier.getAmount();
}

for(AttributeModifier modifier : collection) {
if(modifier.getOperation() == AttributeModifier.Operation.MULTIPLY_TOTAL)
if(modifier.getOperation() == AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL)
value += value * modifier.getAmount();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class DeliverFetchedItemGoal extends FollowOwnerGoal {
private final Shiba shiba;
private int timeTilNextJump = 20;

public DeliverFetchedItemGoal(Shiba shiba, double speed, float minDist, float maxDist, boolean teleportToLeaves) {
super(shiba, speed, minDist, maxDist, teleportToLeaves);
public DeliverFetchedItemGoal(Shiba shiba, double speed, float minDist, float maxDist) {
super(shiba, speed, minDist, maxDist);
this.shiba = shiba;
}

Expand Down
22 changes: 9 additions & 13 deletions src/main/java/org/violetmoon/quark/content/mobs/entity/Crab.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,24 +175,20 @@ public float getWalkTargetValue(BlockPos pos, LevelReader world) {
return world.getBlockState(pos.below()).is(CrabsModule.crabSpawnableTag) ? 10.0F : world.getRawBrightness(pos, 0) - 0.5F;
}

@Override
public boolean canBreatheUnderwater() {
return true;
}

@NotNull
@Override
public MobType getMobType() {
return MobType.ARTHROPOD;
}

@Override
protected void defineSynchedData() {
super.defineSynchedData();
entityData.define(SIZE_MODIFIER, 1f);
entityData.define(VARIANT, -1);
entityData.define(RAVING, false);
entityData.define(FROM_BUCKET, false);
protected void defineSynchedData(SynchedEntityData.Builder builder) {
super.defineSynchedData(builder);

builder.define(SIZE_MODIFIER, 1f);
builder.define(VARIANT, -1);
builder.define(RAVING, false);
builder.define(FROM_BUCKET, false);
}

@NotNull
Expand Down Expand Up @@ -331,8 +327,8 @@ public void tick() {
}

@Override
public float getStepHeight() {
float baseStep = wasTouchingWater ? 1F : 0.6F;
public float getStepHeight() { //TODO figure out when to recalculate attribute -Partonetrain
float baseStep = isInWater() ? 1F : 0.6F;
AttributeInstance stepHeightAttribute = getAttribute(Attributes.STEP_HEIGHT);
if(stepHeightAttribute != null)
return (float) Math.max(0, baseStep + stepHeightAttribute.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.item.alchemy.PotionUtils;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.providers.VanillaEnchantmentProviders;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.storage.loot.LootTable;
Expand All @@ -58,9 +59,9 @@ public Forgotten(EntityType<? extends Forgotten> type, Level world) {
}

@Override
protected void defineSynchedData() {
super.defineSynchedData();
entityData.define(SHEATHED_ITEM, ItemStack.EMPTY);
protected void defineSynchedData(SynchedEntityData.Builder builder) {
super.defineSynchedData(builder);
builder.define(SHEATHED_ITEM, ItemStack.EMPTY);
}

public static AttributeSupplier.Builder registerAttributes() {
Expand All @@ -72,8 +73,8 @@ public static AttributeSupplier.Builder registerAttributes() {

@Override
@Nullable
public SpawnGroupData finalizeSpawn(@NotNull ServerLevelAccessor worldIn, @NotNull DifficultyInstance difficultyIn, @NotNull MobSpawnType reason, @Nullable SpawnGroupData spawnDataIn, @Nullable CompoundTag dataTag) {
SpawnGroupData ilivingentitydata = super.finalizeSpawn(worldIn, difficultyIn, reason, spawnDataIn, dataTag);
public SpawnGroupData finalizeSpawn(@NotNull ServerLevelAccessor worldIn, @NotNull DifficultyInstance difficultyIn, @NotNull MobSpawnType reason, @Nullable SpawnGroupData spawnDataIn) {
SpawnGroupData ilivingentitydata = super.finalizeSpawn(worldIn, difficultyIn, reason, spawnDataIn);
reassessWeaponGoal();

return ilivingentitydata;
Expand Down Expand Up @@ -160,12 +161,12 @@ protected void populateDefaultEquipmentSlots(@NotNull RandomSource rand, @NotNul
prepareEquipment();
}

public void prepareEquipment() {
public void prepareEquipment(ServerLevelAccessor serverLevelAccessor, DifficultyInstance difficultyInstance) {
ItemStack bow = new ItemStack(Items.BOW);
ItemStack sheathed = new ItemStack(Items.IRON_SWORD);

EnchantmentHelper.enchantItem(random, bow, 20, false);
EnchantmentHelper.enchantItem(random, sheathed, 20, false);
EnchantmentHelper.enchantItemFromProvider(bow, serverLevelAccessor.registryAccess(), VanillaEnchantmentProviders.MOB_SPAWN_EQUIPMENT, difficultyInstance, random);
EnchantmentHelper.enchantItemFromProvider(sheathed, serverLevelAccessor.registryAccess(), VanillaEnchantmentProviders.MOB_SPAWN_EQUIPMENT, difficultyInstance, random);

if(Quark.ZETA.modules.isEnabled(ColorRunesModule.class) && random.nextBoolean()) {
DyeColor color = DyeColor.values()[random.nextInt(DyeColor.values().length)];
Expand All @@ -185,12 +186,10 @@ public void prepareEquipment() {

@NotNull
@Override
protected AbstractArrow getArrow(@NotNull ItemStack arrowStack, float distanceFactor) {
AbstractArrow arrow = super.getArrow(arrowStack, distanceFactor);
protected AbstractArrow getArrow(@NotNull ItemStack arrowStack, float distanceFactor, @Nullable ItemStack itemStack) {
AbstractArrow arrow = super.getArrow(arrowStack, distanceFactor, itemStack);
if(arrow instanceof Arrow arrowInstance) {
ItemStack stack = new ItemStack(Items.TIPPED_ARROW);
PotionUtils.setCustomEffects(stack, ImmutableSet.of(new MobEffectInstance(MobEffects.BLINDNESS, 100, 0)));
arrowInstance.setEffectsFromItem(stack);
arrowInstance.addEffect(new MobEffectInstance(MobEffects.BLINDNESS, 100, 0));
}

return arrow;
Expand Down
Loading
Loading