Skip to content

Commit

Permalink
1.21 porting ongoing
Browse files Browse the repository at this point in the history
ingame rendering does not work yet
  • Loading branch information
Fallen-Breath committed Jun 18, 2024
1 parent 8573fbd commit 9603c0e
Show file tree
Hide file tree
Showing 20 changed files with 322 additions and 58 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ preprocess {
def mc1202 = createNode('1.20.2', 1_20_02, '')
def mc1204 = createNode('1.20.4', 1_20_04, '')
def mc1206 = createNode('1.20.6', 1_20_06, '')
def mc121 = createNode('1.21' , 1_21_00, '')

mc115.link(mc114, file('versions/mapping-1.15-1.14.txt'))
mc115.link(mc116, file('versions/mapping-1.15-1.16.txt'))
Expand All @@ -36,6 +37,7 @@ preprocess {
mc1201.link(mc1202, file('versions/mapping-1.20.1-1.20.2.txt'))
mc1202.link(mc1204, file('versions/mapping-1.20.2-1.20.4.txt'))
mc1204.link(mc1206, file('versions/mapping-1.20.4-1.20.6.txt'))
mc1206.link(mc121, file('versions/mapping-1.20.6-1.21.txt'))
}

tasks.register('buildAndGather') {
Expand Down
3 changes: 2 additions & 1 deletion settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"1.20.1",
"1.20.2",
"1.20.4",
"1.20.6"
"1.20.6",
"1.21"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;

//#if MC >= 12100
//$$ import net.minecraft.component.ComponentChanges;
//$$ import net.minecraft.util.Util;
//#endif

//#if MC >= 12006
//$$ import net.minecraft.command.argument.ItemStackArgument;
//#endif
Expand All @@ -45,7 +50,18 @@ public static void copyItemData()
ItemStack itemStack = slot.getStack();

//#if MC >= 12006
//$$ var arg = new ItemStackArgument(itemStack.getRegistryEntry(), itemStack.getComponents());
//$$ var arg = new ItemStackArgument(
//$$ itemStack.getRegistryEntry(),
//$$ //#if MC >= 12100
//$$ //$$ Util.make(() -> {
//$$ //$$ var builder = ComponentChanges.builder();
//$$ //$$ itemStack.getComponents().forEach(builder::add);
//$$ //$$ return builder.build();
//$$ //$$ })
//$$ //#else
//$$ itemStack.getComponents()
//$$ //#endif
//$$ );
//$$ String command = String.format("/give @s %s", arg.asString(mc.world.getRegistryManager()));
//#else
String command = String.format("/give @s %s", itemStack.getItem());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import fi.dy.masa.malilib.util.LayerRange;
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs;
import me.fallenbreath.tweakermore.mixins.tweaks.features.schematicProPlace.BlockItemAccessor;
import me.fallenbreath.tweakermore.util.IdentifierUtil;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;

Expand All @@ -40,7 +40,7 @@ public static boolean isItemInRestrictorWhitelist(ItemStack itemStack)
{
return TweakerMoreConfigs.SCHEMATIC_BLOCK_PLACEMENT_RESTRICTION_ITEM_WHITELIST.getStrings().
stream().
map(itemId -> Registry.ITEM.get(new Identifier(itemId))).
map(itemId -> Registry.ITEM.get(IdentifierUtil.of(itemId))).
anyMatch(item -> item == itemStack.getItem());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private static void renderQuestionMark(

//#if MC >= 11500
textMatrixStack.translate(0.0, 0.0, zOffset);
VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
VertexConsumerProvider.Immediate immediate = RenderUtil.getVertexConsumer();
textRenderer.draw(
text,
textX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
public abstract class BeaconBlockEntityRendererMixin
{
@Inject(
//#if MC >= 11700
//#if MC >= 12100
//$$ method = "renderBeam(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/util/Identifier;FFJIIIFF)V",
//#elseif MC >= 11700
//$$ method = "renderBeam(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;FJII[F)V",
//#elseif MC >= 11500
method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;FJII[F)V",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ private int tweakerMore_scoreboardSideBarScale_push(
return centerY;
}

@Inject(method = "renderScoreboardSidebar", at = @At("RETURN"))
@Inject(
//#if MC >= 12006
//$$ method = "renderScoreboardSidebar(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/scoreboard/ScoreboardObjective;)V",
//#else
method = "renderScoreboardSidebar",
//#endif
at = @At("RETURN")
)
private void tweakerMore_scoreboardSideBarScale_pop(CallbackInfo ci)
{
if (this.scaler != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,41 @@

package me.fallenbreath.tweakermore.mixins.util.render;

import com.llamalad7.mixinextras.sugar.Local;
import me.fallenbreath.tweakermore.util.render.RenderUtil;
import net.minecraft.client.render.GameRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

//#if MC >= 12100
//$$ import net.minecraft.client.render.RenderTickCounter;
//#endif

@Mixin(GameRenderer.class)
public abstract class GameRendererMixin
{
@Inject(method = "render", at = @At("HEAD"))
private void recordTickDelta(float tickDelta, long startTime, boolean tick, CallbackInfo ci)
private void recordTickDelta_renderStart(
CallbackInfo ci,
//#if MC >= 12100
//$$ @Local(argsOnly = true) RenderTickCounter tickCounter
//#else
@Local(argsOnly = true) float tickDelta
//#endif
)
{
RenderUtil.tickDelta = tickDelta;
RenderUtil.tickDelta =
//#if MC >= 12100
//$$ tickCounter.getTickDelta(false);
//#else
tickDelta;
//#endif
}

@Inject(method = "render", at = @At("TAIL"))
private void recordTickDelta(CallbackInfo ci)
private void recordTickDelta_renderEnd(CallbackInfo ci)
{
RenderUtil.tickDelta = 1.0F;
}
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/me/fallenbreath/tweakermore/util/IdentifierUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of the TweakerMore project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* TweakerMore is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TweakerMore is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with TweakerMore. If not, see <https://www.gnu.org/licenses/>.
*/

package me.fallenbreath.tweakermore.util;

import net.minecraft.util.Identifier;

public class IdentifierUtil
{
public static Identifier of(String id)
{
//#if MC >= 12100
//$$ return Identifier.of(id);
//#else
return new Identifier(id);
//#endif
}

public static Identifier of(String namespace, String path)
{
//#if MC >= 12100
//$$ return Identifier.of(namespace, path);
//#else
return new Identifier(namespace, path);
//#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,12 @@

package me.fallenbreath.tweakermore.util;

import me.fallenbreath.tweakermore.TweakerMoreMod;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

public class RegistryUtil
{
public static Identifier id(String path)
{
return new Identifier(TweakerMoreMod.MOD_ID, path);
}

public static String getItemId(Item item)
{
return Registry.ITEM.getId(item).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,33 @@
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.Difficulty;
import net.minecraft.world.explosion.Explosion;

import java.util.Objects;

//#if MC >= 12100
//$$ import net.minecraft.enchantment.Enchantments;
//#endif

//#if MC >= 11904
//$$ import net.minecraft.registry.tag.DamageTypeTags;
//#endif

@SuppressWarnings("UnusedReturnValue")
public class DamageCalculator
{
private final LivingEntity entity;
private float damageAmount;
private final DamageSource damageSource;

//#if MC < 12100
@SuppressWarnings("FieldCanBeLocal")
//#endif
private ServerWorld serverWorld = null;

private ApplyStage currentStage;

private DamageCalculator(LivingEntity entity, float damageAmount, DamageSource damageSource)
Expand All @@ -54,6 +65,12 @@ private DamageCalculator(LivingEntity entity, float damageAmount, DamageSource d
this.currentStage = ApplyStage.NONE;
}

// mc1.21+ EPF calculation needs this
public void setServerWorld(ServerWorld serverWorld)
{
this.serverWorld = serverWorld;
}

/*
* ============================
* Factories
Expand Down Expand Up @@ -168,12 +185,21 @@ public DamageCalculator applyArmorAndResistanceAndEnchantment()
))
{
amount = DamageUtil.getDamageLeft(
//#if MC >= 12100
//$$ this.entity,
//#endif
amount,
//#if MC >= 12006
//$$ this.damageSource,
//#endif
this.entity.getArmor(),
(float)this.entity.getAttributeInstance(EntityAttributes.ARMOR_TOUGHNESS).getValue()

(float)this.entity.
//#if MC >= 11600
//$$ getAttributeValue(EntityAttributes.GENERIC_ARMOR_TOUGHNESS)
//#else
getAttributeInstance(EntityAttributes.ARMOR_TOUGHNESS).getValue()
//#endif
);
}

Expand All @@ -199,12 +225,21 @@ public DamageCalculator applyArmorAndResistanceAndEnchantment()
amount = Math.max(amount * (1 - level / 5.0F), 0.0F);
}

if (amount > 0.0F)
//noinspection PointlessBooleanExpression
if (amount > 0.0F && !(
//#if MC >= 11904
//$$ this.damageSource.isIn(DamageTypeTags.BYPASSES_ENCHANTMENTS)
//#elseif MC >= 11902
//$$ this.damageSource.bypassesProtection()
//#else
false
//#endif
))
{
int level = EnchantmentHelper.getProtectionAmount(this.entity.getArmorItems(), this.damageSource);
float level = this.calculateProtectionEnchantmentAmount();
if (level > 0)
{
amount = DamageUtil.getInflictedDamage(amount, (float) level);
amount = DamageUtil.getInflictedDamage(amount, level);
}
}
}
Expand All @@ -214,6 +249,61 @@ public DamageCalculator applyArmorAndResistanceAndEnchantment()
return this;
}

private float calculateProtectionEnchantmentAmount()
{
//#if MC >= 12100
//$$ if (this.serverWorld != null)
//$$ {
//$$ return EnchantmentHelper.getProtectionAmount(this.serverWorld, this.entity, this.damageSource);
//$$ }
//$$ else
//$$ {
//$$ // it's impossible do this client-side
//$$ // what we can do best, is to simulate the basic legacy vanilla behavior
//$$
//$$ // reference: mc1.20.6 net.minecraft.enchantment.ProtectionEnchantment.getProtectionAmount
//$$ var source = this.damageSource;
//$$ if (source.isIn(DamageTypeTags.BYPASSES_INVULNERABILITY))
//$$ {
//$$ return 0;
//$$ }
//$$
//$$ float epf = 0;
//$$ for (var item : this.entity.getAllArmorItems())
//$$ {
//$$ for (var enchantmentEntry : item.getEnchantments().getEnchantmentEntries())
//$$ {
//$$ var enchantment = enchantmentEntry.getKey();
//$$ int level = enchantmentEntry.getIntValue();
//$$ if (enchantment == Enchantments.PROTECTION)
//$$ {
//$$ epf += level;
//$$ }
//$$ else if (enchantment == Enchantments.FIRE_PROTECTION && source.isIn(DamageTypeTags.IS_FIRE))
//$$ {
//$$ epf += level * 2;
//$$ }
//$$ else if (enchantment == Enchantments.FEATHER_FALLING && source.isIn(DamageTypeTags.IS_FALL))
//$$ {
//$$ epf += level * 3;
//$$ }
//$$ else if (enchantment == Enchantments.BLAST_PROTECTION && source.isIn(DamageTypeTags.IS_EXPLOSION))
//$$ {
//$$ epf += level * 2;
//$$ }
//$$ else if (enchantment == Enchantments.PROJECTILE_PROTECTION && source.isIn(DamageTypeTags.IS_PROJECTILE))
//$$ {
//$$ epf += level * 2;
//$$ }
//$$ }
//$$ }
//$$ return epf;
//$$ }
//#else
return EnchantmentHelper.getProtectionAmount(this.entity.getArmorItems(), this.damageSource);
//#endif
}

public DamageCalculator applyAbsorption()
{
this.checkAndSetStage(ApplyStage.ABSORPTION);
Expand Down
Loading

0 comments on commit 9603c0e

Please sign in to comment.