Skip to content

Commit

Permalink
21 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaMode committed Feb 29, 2024
1 parent 38581b3 commit 73f8611
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/main/java/slimeknights/tconstruct/FabricEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class FabricEvents {
public static void init() {
FluidEvents.onFurnaceFuel();
FluidEvents.init();
ToolEvents.init();
CommonsEvents.init();
AchievementEvents.init();
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/slimeknights/tconstruct/fluids/FluidEvents.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package slimeknights.tconstruct.fluids;

import io.github.fabricators_of_create.porting_lib.fluids.FluidStack;
import net.fabricmc.fabric.api.registry.FuelRegistry;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
import net.minecraft.world.item.Items;
import slimeknights.tconstruct.fluids.util.ConstantFluidContainerWrapper;

/**
* Event subscriber for modifier events
* Note the way the subscribers are set up, technically works on anything that has the tic_modifiers tag
*/
@SuppressWarnings("unused")
public class FluidEvents {
public static void init() {
onFurnaceFuel();
FluidStorage.ITEM.registerForItems((itemStack, context) -> new ConstantFluidContainerWrapper(new FluidStack(TinkerFluids.powderedSnow.get(), FluidConstants.BUCKET), Items.BUCKET.getDefaultInstance(), context), Items.POWDER_SNOW_BUCKET);
}

public static void onFurnaceFuel() {
// if (event.getItemStack().getItem() == TinkerFluids.blazingBlood.asItem()) {
// // 150% efficiency compared to lava bucket, compare to casting blaze rods, which cast into 120%
// event.setBurnTime(30000);
// }
FuelRegistry.INSTANCE.add(TinkerFluids.blazingBlood.asItem(), 30000);
}

@SubscribeEvent
static void attachCapabilities(AttachCapabilitiesEvent<ItemStack> event) {
ItemStack stack = event.getObject();
if (event.getObject().is(Items.POWDER_SNOW_BUCKET)) {
event.addCapability(
TConstruct.getResource("powdered_snow"),
new ConstantFluidContainerWrapper(new FluidStack(TinkerFluids.powderedSnow.get(), FluidAttributes.BUCKET_VOLUME), Items.BUCKET.getDefaultInstance()));
}
}
}
16 changes: 3 additions & 13 deletions src/main/java/slimeknights/tconstruct/fluids/TinkerFluids.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,8 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.DispenserBlock;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.common.ForgeMod;
import net.minecraftforge.common.brewing.BrewingRecipe;
import net.minecraftforge.common.brewing.BrewingRecipeRegistry;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.ForgeFlowingFluid;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
import net.minecraftforge.registries.DataSerializerEntry;
import net.minecraftforge.registries.RegistryObject;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.material.PushReaction;
import slimeknights.mantle.fluid.UnplaceableFluid;
import slimeknights.mantle.fluid.attributes.FluidAttributes;
import slimeknights.mantle.registration.ItemProperties;
Expand Down Expand Up @@ -84,7 +74,7 @@ public TinkerFluids() {
.build()).stacksTo(1).craftRemainder(Items.GLASS_BOTTLE),
() -> new FluidStack(venom.get(), FluidValues.BOTTLE))
);
public static final RegistryObject<UnplaceableFluid> powderedSnow = FLUIDS.registerFluid("powdered_snow", () -> new UnplaceableFluid(Items.POWDER_SNOW_BUCKET.delegate, FluidAttributes.builder(TConstruct.getResource("block/fluid/powdered_snow/still"), TConstruct.getResource("block/fluid/powdered_snow/flowing")).sound(SoundEvents.BUCKET_FILL, SoundEvents.BUCKET_EMPTY).temperature(270)));
public static final RegistryObject<UnplaceableFluid> powderedSnow = FLUIDS.registerFluid("powdered_snow", () -> new UnplaceableFluid(() -> Items.POWDER_SNOW_BUCKET, FluidAttributes.builder(TConstruct.getResource("block/fluid/powdered_snow/still"), TConstruct.getResource("block/fluid/powdered_snow/flowing")).sound(SoundEvents.BUCKET_FILL, SoundEvents.BUCKET_EMPTY).temperature(270)));

// slime - note second name parameter is forge tag name
public static final FluidObject<SimpleFlowableFluid> earthSlime = FLUIDS.register("earth_slime", "slime", coolBuilder().density(1400).viscosity(1400).temperature(350), properties -> properties.mapColor(MapColor.WATER).replaceable().pushReaction(PushReaction.DESTROY).liquid(), SlimeFluid.Source::new, SlimeFluid.Flowing::new, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package slimeknights.tconstruct.library.events.teleport;

import io.github.fabricators_of_create.porting_lib.entity.events.EntityEvents;
import lombok.Getter;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.event.entity.EntityTeleportEvent;
import net.minecraftforge.eventbus.api.Cancelable;
import slimeknights.tconstruct.library.modifiers.ModifierEntry;
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;

/** Event fired when an entity teleports using the ender sling modifier */
@Cancelable
public class SlingModifierTeleportEvent extends EntityTeleportEvent {
public class SlingModifierTeleportEvent extends EntityEvents.Teleport.EntityTeleportEvent {
public static final Event<SlingEvent> SLING_MODIFIER_TELEPORT = EventFactory.createArrayBacked(SlingEvent.class, callbacks -> event -> {
for (SlingEvent e : callbacks)
e.onSlingModifierTeleport(event);
});

@Getter
private final IToolStackView tool;
@Getter
Expand All @@ -19,4 +24,14 @@ public SlingModifierTeleportEvent(Entity entity, double targetX, double targetY,
this.tool = tool;
this.entry = entry;
}

@Override
public void sendEvent() {
SLING_MODIFIER_TELEPORT.invoker().onSlingModifierTeleport(this);
}

@FunctionalInterface
public interface SlingEvent {
void onSlingModifierTeleport(SlingModifierTeleportEvent event);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package slimeknights.tconstruct.library.json.variable.entity;

import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraftforge.registries.ForgeRegistries;
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader;
import slimeknights.mantle.data.loader.RegistryEntryLoader;

/** Variable that fetches an attribute value */
public record AttributeEntityVariable(Attribute attribute) implements EntityVariable {
public static final IGenericLoader<AttributeEntityVariable> LOADER = new RegistryEntryLoader<>("attribute", ForgeRegistries.ATTRIBUTES, AttributeEntityVariable::new, AttributeEntityVariable::attribute);
public static final IGenericLoader<AttributeEntityVariable> LOADER = new RegistryEntryLoader<>("attribute", BuiltInRegistries.ATTRIBUTE, AttributeEntityVariable::new, AttributeEntityVariable::attribute);

@Override
public float getValue(LivingEntity entity) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package slimeknights.tconstruct.library.json.variable.entity;

import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.LivingEntity;
import net.minecraftforge.registries.ForgeRegistries;
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader;
import slimeknights.mantle.data.loader.RegistryEntryLoader;

/** Gets the level of the mob effect on an entity */
public record EntityEffectLevelVariable(MobEffect effect) implements EntityVariable {
public static final IGenericLoader<EntityEffectLevelVariable> LOADER = new RegistryEntryLoader<>("effect", ForgeRegistries.MOB_EFFECTS, EntityEffectLevelVariable::new, EntityEffectLevelVariable::effect);
public static final IGenericLoader<EntityEffectLevelVariable> LOADER = new RegistryEntryLoader<>("effect", BuiltInRegistries.MOB_EFFECT, EntityEffectLevelVariable::new, EntityEffectLevelVariable::effect);

@Override
public float getValue(LivingEntity entity) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package slimeknights.tconstruct.library.modifiers.modules.combat;

import com.google.gson.JsonObject;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation;
import net.minecraftforge.registries.ForgeRegistries;
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader;
import slimeknights.mantle.util.JsonHelper;
import slimeknights.tconstruct.library.json.LevelingValue;
Expand Down Expand Up @@ -92,7 +92,7 @@ public IGenericLoader<? extends ModifierModule> getLoader() {
public MeleeAttributeModule deserialize(JsonObject json) {
return new MeleeAttributeModule(
GsonHelper.getAsString(json, "unique"),
JsonHelper.getAsEntry(ForgeRegistries.ATTRIBUTES, json, "attribute"),
JsonHelper.getAsEntry(BuiltInRegistries.ATTRIBUTE, json, "attribute"),
JsonHelper.getAsEnum(json, "operation", Operation.class),
LevelingValue.deserialize(json),
ModifierModuleCondition.deserializeFrom(json)
Expand All @@ -103,7 +103,7 @@ public MeleeAttributeModule deserialize(JsonObject json) {
public void serialize(MeleeAttributeModule object, JsonObject json) {
object.condition.serializeInto(json);
json.addProperty("unique", object.unique);
json.addProperty("attribute", Objects.requireNonNull(object.attribute.getRegistryName()).toString());
json.addProperty("attribute", Objects.requireNonNull(BuiltInRegistries.ATTRIBUTE.getKey(object.attribute)).toString());
json.addProperty("operation", object.operation.name().toLowerCase(Locale.ROOT));
object.amount.serialize(json);
}
Expand All @@ -112,7 +112,7 @@ public void serialize(MeleeAttributeModule object, JsonObject json) {
public MeleeAttributeModule fromNetwork(FriendlyByteBuf buffer) {
return new MeleeAttributeModule(
buffer.readUtf(Short.MAX_VALUE),
buffer.readRegistryIdUnsafe(ForgeRegistries.ATTRIBUTES),
BuiltInRegistries.ATTRIBUTE.byId(buffer.readVarInt()),
buffer.readEnum(Operation.class),
LevelingValue.fromNetwork(buffer),
ModifierModuleCondition.fromNetwork(buffer)
Expand All @@ -122,7 +122,7 @@ public MeleeAttributeModule fromNetwork(FriendlyByteBuf buffer) {
@Override
public void toNetwork(MeleeAttributeModule object, FriendlyByteBuf buffer) {
buffer.writeUtf(object.unique);
buffer.writeRegistryIdUnsafe(ForgeRegistries.ATTRIBUTES, object.attribute);
buffer.writeVarInt(BuiltInRegistries.ATTRIBUTE.getId(object.attribute));
buffer.writeEnum(object.operation);
object.amount.toNetwork(buffer);
object.condition.toNetwork(buffer);
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/slimeknights/tconstruct/shared/TinkerClient.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
package slimeknights.tconstruct.shared;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexFormat;
import io.github.fabricators_of_create.porting_lib.event.common.RecipesUpdatedCallback;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.BlockPos;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.level.block.state.BlockState;
import org.joml.Matrix4f;
import slimeknights.mantle.registration.FluidAttributeClientHandler;
import slimeknights.mantle.registration.FluidAttributeHandler;
import slimeknights.tconstruct.common.TinkerTags;
import slimeknights.tconstruct.common.config.Config;
import slimeknights.tconstruct.common.recipe.RecipeCacheInvalidator;
import slimeknights.tconstruct.fluids.FluidClientEvents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.material.PushReaction;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -365,11 +365,9 @@ public final class TinkerSmeltery extends TinkerModule {

public TinkerSmeltery() {
registerSerializers();
event.enqueueWork(() -> {
Consumer<Block> dispenserBehavior = block -> DispenserBlock.registerBehavior(block.asItem(), PlaceBlockDispenserBehavior.INSTANCE);
searedTank.forEach(dispenserBehavior);
scorchedTank.forEach(dispenserBehavior);
});
Consumer<Block> dispenserBehavior = block -> DispenserBlock.registerBehavior(block.asItem(), PlaceBlockDispenserBehavior.INSTANCE);
searedTank.forEach(dispenserBehavior);
scorchedTank.forEach(dispenserBehavior);
}

void registerSerializers() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package slimeknights.tconstruct.tools.item;

import io.github.fabricators_of_create.porting_lib.tool.ToolActions;
import net.minecraft.ChatFormatting;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -28,7 +29,8 @@
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.ToolActions;
import net.minecraft.world.phys.Vec3;
import org.joml.Quaternionf;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.modifiers.ModifierEntry;
import slimeknights.tconstruct.library.modifiers.TinkerHooks;
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/slimeknights/tconstruct/tools/logic/ToolEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ public class ToolEvents {
public static void init() {
PlayerEvents.BREAK_SPEED.register(ToolEvents::onBreakSpeed);
ToolHarvestEvent.EVENT.register(ToolEvents::onHarvest);
LivingEntityEvents.HURT.register(ToolEvents::enderDragonDamage);
LivingEntityEvents.HURT.register(ToolEvents::livingAttack);
LivingEntityEvents.ATTACK.register(ToolEvents::livingAttack);
LivingEntityEvents.HURT.register(ToolEvents::livingHurt);
LivingEntityEvents.TICK.register(ToolEvents::livingWalk);
LivingVisibilityEvent.VISIBILITY.register(ToolEvents::livingVisibility);
Expand Down Expand Up @@ -189,16 +188,15 @@ static void onHarvest(ToolHarvestEvent event) {
}

@SubscribeEvent(priority = EventPriority.LOW)
static void livingAttack(LivingAttackEvent event) {
LivingEntity entity = event.getEntityLiving();
static boolean livingAttack(LivingEntity entity, DamageSource source, float amount) {
// client side always returns false, so this should be fine?
if (entity.level().isClientSide() || entity.isDeadOrDying()) {
return amount;
return false;
}
// I cannot think of a reason to run when invulnerable
// DamageSource source = event.getSource();
if (entity.isInvulnerableTo(source)) {
return amount;
return false;
}

// a lot of counterattack hooks want to detect direct attacks, so save time by calculating once
Expand All @@ -215,7 +213,7 @@ static void livingAttack(LivingAttackEvent event) {
if (toolStack != null && !toolStack.isBroken()) {
for (ModifierEntry entry : toolStack.getModifierList()) {
if (entry.getHook(TinkerHooks.DAMAGE_BLOCK).isDamageBlocked(toolStack, entry, context, slotType, source, amount)) {
return 0;
return true;
}
}
}
Expand All @@ -241,7 +239,7 @@ static void livingAttack(LivingAttackEvent event) {
}
}
}
return amount;
return false;
}

/**
Expand Down Expand Up @@ -272,8 +270,7 @@ static float livingHurt(DamageSource source, LivingEntity entity, float original
originalDamage = ModifyDamageModifierHook.modifyDamageTaken(TinkerHooks.MODIFY_HURT, context, source, originalDamage, DamageTakenModifierHook.isDirectDamage(source));
event.setAmount(originalDamage);
if (originalDamage <= 0) {
event.setCanceled(true);
return;
return 0;
}

// remaining logic is reducing damage like vanilla protection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public boolean onStoppedUsing(IToolStackView tool, ModifierEntry modifier, Livin
// get furthest teleportable block
if (furthestPos != null) {
SlingModifierTeleportEvent event = new SlingModifierTeleportEvent(player, furthestPos.getX() + 0.5f, furthestPos.getY(), furthestPos.getZ() + 0.5f, tool, modifier);
MinecraftForge.EVENT_BUS.post(event);
event.sendEvent();
if (!event.isCanceled()) {
player.teleportTo(event.getTargetX(), event.getTargetY(), event.getTargetZ());

// particle effect from EnderPearlEntity
for (int i = 0; i < 32; ++i) {
entity.level().addParticle(ParticleTypes.PORTAL, player.getX(), player.getY() + entity.level().random.nextDouble() * 2.0D, player.getZ(), entity.level().random.nextGaussian(), 0.0D, entity.level.random.nextGaussian());
entity.level().addParticle(ParticleTypes.PORTAL, player.getX(), player.getY() + entity.level().random.nextDouble() * 2.0D, player.getZ(), entity.level().random.nextGaussian(), 0.0D, entity.level().random.nextGaussian());
}
entity.level().playSound(null, player.getX(), player.getY(), player.getZ(), Sounds.SLIME_SLING_TELEPORT.getSound(), player.getSoundSource(), 1f, 1f);
player.causeFoodExhaustion(0.2F);
Expand Down

0 comments on commit 73f8611

Please sign in to comment.