Skip to content

Commit

Permalink
added playertickcallbacks to ComonEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Dec 13, 2023
1 parent ade52a8 commit 3640171
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 0 deletions.
9 changes: 9 additions & 0 deletions common/src/main/java/muramasa/antimatter/Antimatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import muramasa.antimatter.client.AntimatterModelManager;
import muramasa.antimatter.client.ClientData;
import muramasa.antimatter.common.event.CommonEvents;
import muramasa.antimatter.cover.ICover;
import muramasa.antimatter.data.AntimatterDefaultTools;
import muramasa.antimatter.data.AntimatterMaterialTypes;
Expand All @@ -21,9 +22,11 @@
import muramasa.antimatter.item.interaction.CauldronInteractions;
import muramasa.antimatter.machine.MachineState;
import muramasa.antimatter.material.*;
import muramasa.antimatter.mixin.LivingEntityAccessor;
import muramasa.antimatter.network.AntimatterNetwork;
import muramasa.antimatter.ore.BlockOre;
import muramasa.antimatter.ore.StoneType;
import muramasa.antimatter.pipe.BlockFluidPipe;
import muramasa.antimatter.proxy.ClientHandler;
import muramasa.antimatter.proxy.IProxyHandler;
import muramasa.antimatter.proxy.ServerHandler;
Expand All @@ -44,6 +47,7 @@
import muramasa.antimatter.worldgen.AntimatterWorldGenerator;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ItemLike;
Expand Down Expand Up @@ -154,6 +158,11 @@ public void onRegistrationEvent(RegistrationEvent event, Side side) {
AntimatterRecipeSerializer.init();
IngredientSerializer.init();
PropertyIngredient.Serializer.init();
CommonEvents.addPlayerTickCallback((end, logicalServer, player) -> {
if (end && logicalServer && !player.isCreative() && player.getInventory().contains(AntimatterMaterialTypes.INGOT_HOT.getTag())){
BlockFluidPipe.applyTemperatureDamage(player, 1700, 1.0f, 1.0f);
}
});
} else if (event == RegistrationEvent.WORLDGEN_INIT) {
AntimatterWorldGenerator.init();
AntimatterDefaultTools.postInit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package muramasa.antimatter.common.event;

import lombok.Getter;
import muramasa.antimatter.AntimatterAPI;
import muramasa.antimatter.AntimatterConfig;
import muramasa.antimatter.blockentity.pipe.BlockEntityPipe;
Expand Down Expand Up @@ -33,7 +34,18 @@
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;

import java.util.ArrayList;
import java.util.List;

public class CommonEvents {
@Getter
static final List<PlayerTickCallback> PLAYER_TICK_CALLBACKS = new ArrayList<>();

public static void addPlayerTickCallback(PlayerTickCallback callback){
PLAYER_TICK_CALLBACKS.add(callback);
}


public static void lootTableLoad(LootTable table, ResourceLocation name){
if (AntimatterPlatformUtils.getLootTableID(table).getPath().startsWith("blocks/")) {
ResourceLocation blockId = new ResourceLocation(AntimatterPlatformUtils.getLootTableID(table).getNamespace(), name.getPath().replace("blocks/", ""));
Expand Down Expand Up @@ -110,4 +122,8 @@ public static void tagsEvent() {
AntimatterDynamics.onRecipeCompile(true, Minecraft.getInstance().getConnection().getRecipeManager());
}
}

public interface PlayerTickCallback{
void onTick(boolean end, boolean logicalServer, Player player);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package muramasa.antimatter.mixin;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.LivingEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(LivingEntity.class)
public interface LivingEntityAccessor {
@Accessor
BlockPos getLastPos();
}
1 change: 1 addition & 0 deletions common/src/main/resources/antimatter.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"IngredientAccessor",
"ItemStackMixin",
"LeavesBlockMixin",
"LivingEntityAccessor",
"PlayerMixin",
"RecipeManagerMixin",
"RepairItemRecipeMixin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import earth.terrarium.botarium.fabric.fluid.storage.FabricBlockFluidContainer;
import io.github.fabricators_of_create.porting_lib.event.common.BlockPlaceCallback;
import io.github.fabricators_of_create.porting_lib.event.common.ItemCraftedCallback;
import io.github.fabricators_of_create.porting_lib.event.common.PlayerTickEvents;
import muramasa.antimatter.Antimatter;
import muramasa.antimatter.AntimatterAPI;
import muramasa.antimatter.Ref;
Expand Down Expand Up @@ -40,6 +41,7 @@
import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid;
Expand Down Expand Up @@ -78,6 +80,8 @@ public void initialize(boolean run){
CommonEvents.placeBlock(placedOff, context.getPlayer(), context.getLevel(), context.getClickedPos(), context.getLevel().getBlockState(context.getClickedPos()));
return InteractionResult.PASS;
});
PlayerTickEvents.START.register(player -> CommonEvents.getPLAYER_TICK_CALLBACKS().forEach(c -> c.onTick(false, player instanceof ServerPlayer, player)));
PlayerTickEvents.END.register(player -> CommonEvents.getPLAYER_TICK_CALLBACKS().forEach(c -> c.onTick(true, player instanceof ServerPlayer, player)));
RRPCallback.AFTER_VANILLA.register(resources -> AntimatterDynamics.addResourcePacks(resources::add));
RRPCallback.BEFORE_USER.register(resources -> AntimatterDynamics.addDataPacks(resources::add));
Antimatter.LOGGER.info("initializing");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.server.ServerLifecycleHooks;

Expand Down Expand Up @@ -74,6 +75,13 @@ public static void onLootTableLoad(LootTableLoadEvent event) {
CommonEvents.lootTableLoad(event.getTable(), event.getName());
}

@SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event){
CommonEvents.getPLAYER_TICK_CALLBACKS().forEach(c -> {
c.onTick(event.phase == TickEvent.Phase.END, event.side == LogicalSide.SERVER, event.player);
});
}

@SubscribeEvent
public static void remapMissingBlocks(final RegistryEvent.MissingMappings<Block> event) {
for (String modid : AntimatterRemapping.getRemappingMap().keySet()) {
Expand Down

0 comments on commit 3640171

Please sign in to comment.