Finish backporting libzontreck to 1.18.2
This commit is contained in:
parent
c5637d7c44
commit
55acbd4868
21 changed files with 80 additions and 227 deletions
|
@ -13,13 +13,11 @@ import dev.zontreck.eventsbus.Bus;
|
|||
import dev.zontreck.libzontreck.chestgui.ChestGUIRegistry;
|
||||
import dev.zontreck.libzontreck.currency.Bank;
|
||||
import dev.zontreck.libzontreck.currency.CurrencyHelper;
|
||||
import dev.zontreck.libzontreck.items.CreativeModeTabs;
|
||||
import dev.zontreck.libzontreck.items.ModItems;
|
||||
import dev.zontreck.libzontreck.menus.ChestGUIScreen;
|
||||
import dev.zontreck.libzontreck.types.ModMenuTypes;
|
||||
import dev.zontreck.libzontreck.networking.NetworkEvents;
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.minecraftforge.registries.RegisterEvent;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
package dev.zontreck.libzontreck.blocks;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
/**
|
||||
* Code partially taken from HT's TreeChop
|
||||
* <p>
|
||||
* <a href="https://github.com/hammertater/treechop/blob/main/shared/src/main/java/ht/treechop/common/block/BlockImitator.java">Source Material</a>
|
||||
*/
|
||||
public abstract class BlockImitation extends Block
|
||||
{
|
||||
public BlockImitation(Properties pProperties) {
|
||||
super(pProperties);
|
||||
}
|
||||
|
||||
|
||||
public abstract BlockState getImitatedBlockState(BlockGetter level, BlockPos pos);
|
||||
|
||||
public abstract void updateImitation(BlockState newState, BlockGetter level, BlockPos pos);
|
||||
|
||||
@Override
|
||||
public void animateTick(BlockState blockState, Level level, BlockPos pos, RandomSource random) {
|
||||
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||
imitatedBlockState.getBlock().animateTick(imitatedBlockState, level, pos, random);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stepOn(Level level, BlockPos pos, BlockState blockState, Entity entity) {
|
||||
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||
imitatedBlockState.getBlock().stepOn(level, pos, imitatedBlockState, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fallOn(Level level, BlockState blockState, BlockPos pos, Entity entity, float speed) {
|
||||
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||
imitatedBlockState.getBlock().fallOn(level, imitatedBlockState, pos, entity, speed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCloneItemStack(BlockGetter level, BlockPos pos, BlockState blockState) {
|
||||
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||
return imitatedBlockState.getBlock().getCloneItemStack(level, pos, imitatedBlockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePrecipitation(BlockState blockState, Level level, BlockPos pos, Biome.Precipitation precipitation) {
|
||||
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||
imitatedBlockState.getBlock().handlePrecipitation(imitatedBlockState, level, pos, precipitation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightBlock(BlockState blockState, BlockGetter level, BlockPos pos) {
|
||||
return super.getLightBlock(blockState, level, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getShadeBrightness(BlockState blockState, BlockGetter level, BlockPos pos) {
|
||||
return super.getShadeBrightness(blockState, level, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAnalogOutputSignal(BlockState blockState, Level level, BlockPos pos) {
|
||||
return getImitatedBlockState(level, pos).getAnalogOutputSignal(level, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomTick(BlockState blockState, ServerLevel level, BlockPos pos, RandomSource random) {
|
||||
getImitatedBlockState(level, pos).randomTick(level, pos, random);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(BlockState blockState, ServerLevel level, BlockPos pos, RandomSource random) {
|
||||
getImitatedBlockState(level, pos).tick(level, pos, random);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSignal(BlockState blockState, BlockGetter level, BlockPos pos, Direction direction) {
|
||||
return getImitatedBlockState(level, pos).getSignal(level, pos, direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDirectSignal(BlockState blockState, BlockGetter level, BlockPos pos, Direction direction) {
|
||||
return getImitatedBlockState(level, pos).getDirectSignal(level, pos, direction);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package dev.zontreck.libzontreck.chat;
|
||||
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.HoverEvent;
|
||||
import net.minecraft.network.chat.HoverEvent.Action;
|
||||
|
@ -17,7 +18,7 @@ public class HoverTip {
|
|||
*/
|
||||
public static HoverEvent get(String text)
|
||||
{
|
||||
return new HoverEvent(Action.SHOW_TEXT, Component.literal(text));
|
||||
return new HoverEvent(Action.SHOW_TEXT, ChatHelpers.macro(text));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@ import dev.zontreck.libzontreck.items.ModItems;
|
|||
import dev.zontreck.libzontreck.menus.ChestGUIMenu;
|
||||
import dev.zontreck.libzontreck.networking.ModMessages;
|
||||
import dev.zontreck.libzontreck.networking.packets.S2CCloseChestGUI;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.util.ServerUtilities;
|
||||
import dev.zontreck.libzontreck.vectors.Vector2;
|
||||
import dev.zontreck.libzontreck.vectors.Vector2i;
|
||||
|
@ -198,7 +199,7 @@ public class ChestGUI
|
|||
{
|
||||
updateUtilityButtons();
|
||||
MinecraftForge.EVENT_BUS.post(new OpenGUIEvent(id, player, this));
|
||||
NetworkHooks.openScreen(ServerUtilities.getPlayerByID(player.toString()), new SimpleMenuProvider(ChestGUIMenu.getServerMenu(this), Component.literal((MenuTitle != "") ? MenuTitle : "No Title")));
|
||||
NetworkHooks.openGui(ServerUtilities.getPlayerByID(player.toString()), new SimpleMenuProvider(ChestGUIMenu.getServerMenu(this), ChatHelpers.macro(((MenuTitle != "") ? MenuTitle : "No Title"))));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import dev.zontreck.libzontreck.chat.ChatColor;
|
|||
import dev.zontreck.libzontreck.currency.events.TransactionHistoryFlushEvent;
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import net.minecraft.core.UUIDUtil;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
|
|
|
@ -23,9 +23,9 @@ import net.minecraftforge.fml.common.Mod;
|
|||
public class ForgeEventHandlers {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerTick(LivingEvent.LivingTickEvent ev)
|
||||
public void onPlayerTick(LivingEvent.LivingUpdateEvent ev)
|
||||
{
|
||||
if(ev.getEntity().level().isClientSide) return;
|
||||
if(ServerUtilities.isClient()) return;
|
||||
|
||||
if(ev.getEntity() instanceof ServerPlayer player)
|
||||
{
|
||||
|
@ -44,11 +44,11 @@ public class ForgeEventHandlers {
|
|||
@SubscribeEvent
|
||||
public void onPlayerJoin(final PlayerEvent.PlayerLoggedInEvent ev)
|
||||
{
|
||||
if(ev.getEntity().level().isClientSide)return;
|
||||
if(ServerUtilities.isClient())return;
|
||||
|
||||
ServerPlayer player = (ServerPlayer)ev.getEntity();
|
||||
Profile prof = Profile.factory(player);
|
||||
ServerLevel level = player.serverLevel();
|
||||
ServerLevel level = player.getLevel();
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new ProfileLoadedEvent(prof, player, level));
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class ForgeEventHandlers {
|
|||
public void onLeave(final PlayerEvent.PlayerLoggedOutEvent ev)
|
||||
{
|
||||
LibZontreck.LIBZONTRECK_SERVER_AVAILABLE=false; // Yes do this even on the client!
|
||||
if(ev.getEntity().level().isClientSide)return;
|
||||
if(ServerUtilities.isClient()) return;
|
||||
// Get player profile, send disconnect alert, then commit profile and remove it from memory
|
||||
|
||||
try {
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
package dev.zontreck.libzontreck.items;
|
||||
|
||||
import dev.zontreck.libzontreck.LibZontreck;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
//@Mod.EventBusSubscriber(modid = LibZontreck.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class CreativeModeTabs
|
||||
{
|
||||
public static final DeferredRegister<CreativeModeTab> REGISTRY = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, LibZontreck.MOD_ID);
|
||||
|
||||
public static final List<Supplier<? extends ItemLike>> LZ_MOD_ITEMS = new ArrayList<>();
|
||||
|
||||
public static final RegistryObject<CreativeModeTab> LIBZONTRECK_TAB = REGISTRY.register("libzontreck", ()->CreativeModeTab.builder()
|
||||
.title(Component.translatable("itemGroup.tabs.libzontreck"))
|
||||
.icon(Items.BARRIER::getDefaultInstance)
|
||||
.displayItems((display,output)->LZ_MOD_ITEMS.forEach(it->output.accept(it.get())))
|
||||
.build()
|
||||
);
|
||||
|
||||
public static <T extends Item> RegistryObject<T> addToLZTab(RegistryObject<T> item)
|
||||
{
|
||||
LZ_MOD_ITEMS.add(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
public static void register(IEventBus bus)
|
||||
{
|
||||
REGISTRY.register(bus);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package dev.zontreck.libzontreck.menus;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dev.zontreck.libzontreck.LibZontreck;
|
||||
import dev.zontreck.libzontreck.chestgui.ChestGUI;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
@ -35,7 +35,7 @@ public class ChestGUIScreen extends AbstractContainerScreen<ChestGUIMenu> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
||||
public void render(PoseStack pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
||||
this.renderBackground(pGuiGraphics);
|
||||
super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
|
||||
this.renderTooltip(pGuiGraphics, pMouseX, pMouseY);
|
||||
|
@ -50,17 +50,18 @@ public class ChestGUIScreen extends AbstractContainerScreen<ChestGUIMenu> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void renderBg(GuiGraphics guiGraphics, float v, int i, int i1) {
|
||||
protected void renderBg(PoseStack guiGraphics, float v, int i, int i1) {
|
||||
renderBackground(guiGraphics);
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderColor(1,1,1,1);
|
||||
RenderSystem.setShaderTexture(0, TEXTURE);
|
||||
|
||||
guiGraphics.blit(TEXTURE, this.leftPos, this.topPos, 0, 0, imageWidth, imageHeight);
|
||||
blit(guiGraphics, this.leftPos, this.topPos, 0, 0, imageWidth, imageHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderLabels(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY) {
|
||||
pGuiGraphics.drawString(this.font, this.title, this.titleLabelX, this.titleLabelY, 4210752, false);
|
||||
protected void renderLabels(PoseStack pGuiGraphics, int pMouseX, int pMouseY) {
|
||||
|
||||
drawString(pGuiGraphics, this.font, this.title, this.titleLabelX, this.titleLabelY, 4210752);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,21 +49,21 @@ public class ModMessages {
|
|||
|
||||
net.messageBuilder(S2CPlaySoundPacket.class, PACKET_ID.getAndIncrement(), NetworkDirection.PLAY_TO_CLIENT)
|
||||
.decoder(S2CPlaySoundPacket::new)
|
||||
.encoder(S2CPlaySoundPacket::toBytes)
|
||||
.consumerMainThread(S2CPlaySoundPacket::handle)
|
||||
.add();
|
||||
.encoder(S2CPlaySoundPacket::toBytes)
|
||||
.consumer(S2CPlaySoundPacket::handle)
|
||||
.add();
|
||||
|
||||
net.messageBuilder(S2CCloseChestGUI.class, PACKET_ID.getAndIncrement(), NetworkDirection.PLAY_TO_CLIENT)
|
||||
.decoder(S2CCloseChestGUI::new)
|
||||
.encoder(S2CCloseChestGUI::toBytes)
|
||||
.consumerMainThread(S2CCloseChestGUI::handle)
|
||||
.consumer(S2CCloseChestGUI::handle)
|
||||
.add();
|
||||
|
||||
net.messageBuilder(S2CServerAvailable.class, PACKET_ID.getAndIncrement(),
|
||||
NetworkDirection.PLAY_TO_CLIENT)
|
||||
.decoder(S2CServerAvailable::new)
|
||||
.encoder(S2CServerAvailable::toBytes)
|
||||
.consumerMainThread(S2CServerAvailable::handle)
|
||||
.consumer(S2CServerAvailable::handle)
|
||||
.add();
|
||||
|
||||
}
|
||||
|
|
|
@ -48,7 +48,8 @@ public class S2CPlaySoundPacket implements IPacket
|
|||
|
||||
ctx.enqueueWork(()->{
|
||||
// We are on the client now, enqueue the sound!
|
||||
SoundEvent ev = SoundEvent.createFixedRangeEvent(sound, 2.0f);
|
||||
SoundEvent ev = new SoundEvent(sound);
|
||||
|
||||
// Play sound for player!
|
||||
Minecraft.getInstance().player.playSound(ev, 1, BinUtil.getARandomInstance().nextFloat(0, 1));
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@ import net.minecraftforge.registries.RegistryObject;
|
|||
|
||||
public class ModMenuTypes
|
||||
{
|
||||
public static DeferredRegister<MenuType<?>> REGISTRY = DeferredRegister.create(ForgeRegistries.MENU_TYPES, LibZontreck.MOD_ID);
|
||||
public static DeferredRegister<MenuType<?>> REGISTRY = DeferredRegister.create(ForgeRegistries.CONTAINERS, LibZontreck.MOD_ID);
|
||||
|
||||
public static RegistryObject<MenuType<ChestGUIMenu>> CHEST_GUI_MENU = registerMenuType(ChestGUIMenu::new, "chestgui");
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ public class ChatHelpers {
|
|||
*/
|
||||
public static MutableComponent macro(String input, String... inputs)
|
||||
{
|
||||
return Component.literal(macroize(input,inputs));
|
||||
return new TextComponent(macroize(input,inputs));
|
||||
}
|
||||
/**
|
||||
* Returns the output with colors applied, and chat entries replaced using [number] as the format
|
||||
|
|
|
@ -40,7 +40,7 @@ public class ServerUtilities
|
|||
channel.messageBuilder(type, ModMessages.id(), packet.getDirection())
|
||||
.decoder(decoder)
|
||||
.encoder(X::toBytes)
|
||||
.consumerMainThread(X::handle)
|
||||
.consumer(X::handle)
|
||||
.add();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import dev.zontreck.libzontreck.chat.ChatColor;
|
|||
import dev.zontreck.libzontreck.lore.ExtraLore;
|
||||
import dev.zontreck.libzontreck.lore.LoreContainer;
|
||||
import dev.zontreck.libzontreck.lore.LoreEntry;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import dev.zontreck.libzontreck.util.heads.HeadCache.HeadCacheItem;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
@ -28,7 +29,7 @@ public class CreditsEntry {
|
|||
public ItemStack compile()
|
||||
{
|
||||
ItemStack stack = player.getAsItem("");
|
||||
stack.setHoverName(Component.literal(name));
|
||||
stack.setHoverName(ChatHelpers.macro(name));
|
||||
LoreContainer contain = new LoreContainer(stack);
|
||||
contain.clear();
|
||||
LoreEntry.Builder builder = new LoreEntry.Builder();
|
||||
|
|
|
@ -35,7 +35,7 @@ public class WorldPosition {
|
|||
}
|
||||
|
||||
public WorldPosition(ServerPlayer player) {
|
||||
this(new Vector3(player.position()), player.serverLevel());
|
||||
this(new Vector3(player.position()), player.getLevel());
|
||||
}
|
||||
|
||||
public WorldPosition(Vector3 pos, ServerLevel lvl) {
|
||||
|
|
Reference in a new issue