Skip to content

Commit

Permalink
1.21.1 port fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BrokenK3yboard committed Jan 9, 2025
1 parent da1e43e commit 52a86c7
Show file tree
Hide file tree
Showing 30 changed files with 150 additions and 274 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.Sheets;
Expand All @@ -17,16 +16,14 @@
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;

import org.jetbrains.annotations.NotNull;

import org.violetmoon.quark.addons.oddities.entity.TotemOfHoldingEntity;
import org.violetmoon.quark.base.Quark;
import org.violetmoon.quark.base.QuarkClient;

public class TotemOfHoldingRenderer extends EntityRenderer<TotemOfHoldingEntity> {

private static final ModelResourceLocation LOCATION_MODEL = new ModelResourceLocation(Quark.MOD_ID, "extra/totem_of_holding", "inventory");
private static final ModelResourceLocation LOCATION_MODEL = ModelResourceLocation.inventory(Quark.asResource("extra/totem_of_holding"));

public TotemOfHoldingRenderer(EntityRendererProvider.Context context) {
super(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.neoforged.bus.api.Event;
import net.neoforged.bus.api.ICancellableEvent;

public class UsageTickerEvent extends Event {
public class UsageTickerEvent extends Event implements ICancellableEvent {

public final EquipmentSlot slot;
public final ItemStack currentStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraftforge.client.gui.widget.ForgeSlider;
import net.neoforged.neoforge.client.gui.widget.ExtendedSlider;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.violetmoon.quark.base.config.type.RGBAColorConfig;
Expand Down Expand Up @@ -60,10 +60,10 @@ public void addWidgets(ZetaClient zc, Screen parent, ChangeSet changes, SectionD
}

class RGBInputScreen extends AbstractSectionInputScreen {
protected ForgeSlider rslide;
protected ForgeSlider gslide;
protected ForgeSlider bslide;
protected @Nullable ForgeSlider aslide;
protected ExtendedSlider rslide;
protected ExtendedSlider gslide;
protected ExtendedSlider bslide;
protected @Nullable ExtendedSlider aslide;

public RGBInputScreen(ZetaClient zc, Screen parent, ChangeSet changes, SectionDefinition def) {
super(zc, parent, changes, def);
Expand Down Expand Up @@ -99,18 +99,18 @@ protected void forceUpdateWidgets() {

private static final Component EMPTY = Component.empty();

private ForgeSlider makeSliderPlease(int x, int y, int width, int height, ValueDefinition<Double> binding, String label, int labelColor) {
private ExtendedSlider makeSliderPlease(int x, int y, int width, int height, ValueDefinition<Double> binding, String label, int labelColor) {
//TODO: keep this for forge with a platform delegate or copy paste in common
return new ForgeSlider(x, y + 50, width, height, EMPTY, EMPTY, 0f, 1f, 0, 0, 1, false) {
return new ExtendedSlider(x, y + 50, width, height, EMPTY, EMPTY, 0f, 1f, 0, 0, 1, false) {
@Override
protected void applyValue() {
setValue(snap(this));
changes.set(binding, getValue());
}

@Override
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
super.render(guiGraphics, mouseX, mouseY, partialTicks);
public void renderWidget(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
super.renderWidget(guiGraphics, mouseX, mouseY, partialTicks);

//draw the current value
String displayVal = String.format("%.2f", getValue());
Expand All @@ -130,8 +130,7 @@ public void tick() {

@Override
public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
renderBackground(guiGraphics);

renderBackground(guiGraphics, mouseX, mouseY, partialTicks);
super.render(guiGraphics, mouseX, mouseY, partialTicks);

int titleLeft = width / 2;
Expand Down Expand Up @@ -160,7 +159,7 @@ public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, flo
guiGraphics.fill(cx, cy, cx + size, cy + size, color);
}

private double snap(ForgeSlider s) {
private double snap(ExtendedSlider s) {
double val = s.getValue();
val = snap(val, 0.0, s);
val = snap(val, 0.25, s);
Expand All @@ -170,7 +169,7 @@ private double snap(ForgeSlider s) {
return val;
}

private double snap(double val, double target, ForgeSlider s) {
private double snap(double val, double target, ExtendedSlider s) {
if(Math.abs(val - target) < 0.02) {
s.setValue(target);
return target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static boolean renderPistonBlock(PistonMovingBlockEntity piston, float pa
return false;
CompoundTag tileTag = PistonsMoveTileEntitiesModule.getMovingBlockEntityData(piston.getLevel(), truePos);
if(tileTag != null && tile.getType() == BuiltInRegistries.BLOCK_ENTITY_TYPE.get(ResourceLocation.parse(tileTag.getString("id"))))
tile.load(tileTag);
tile.loadWithComponents(tileTag, piston.getLevel().registryAccess());
Vec3 offset = new Vec3(piston.getXOff(partialTicks), piston.getYOff(partialTicks), piston.getZOff(partialTicks));
return renderTESafely(piston.getLevel(), truePos, state, tile, piston, partialTicks, offset, matrix, bufferIn, combinedLightIn, combinedOverlayIn);
}
Expand All @@ -62,7 +62,7 @@ public static boolean renderTESafely(Level world, BlockPos truePos, BlockState s

matrix.translate(offset.x, offset.y, offset.z);

tile.blockState = state;
tile.setBlockState(state);
tileentityrenderer.render(tile, partialTicks, matrix, bufferIn, combinedLightIn, combinedOverlayIn);
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@

package org.violetmoon.quark.content.automation.client.screen;

import java.util.List;

import org.violetmoon.quark.base.Quark;
import org.violetmoon.quark.content.automation.inventory.CrafterMenu;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
Expand All @@ -40,6 +35,10 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.Slot;
import org.violetmoon.quark.base.Quark;
import org.violetmoon.quark.content.automation.inventory.CrafterMenu;

import java.util.List;

public class CrafterScreen extends AbstractContainerScreen<CrafterMenu> {
private static final ResourceLocation TEXTURE = Quark.asResource("textures/gui/container/crafter.png");
Expand All @@ -56,7 +55,7 @@ public void init() {

@Override
public void render(GuiGraphics context, int mouseX, int mouseY, float delta) {
renderBackground(context);
renderBackground(context, mouseX, mouseY, delta);
super.render(context, mouseX, mouseY, delta);
this.renderTooltip(context, mouseX, mouseY);
if (menu.getCarried().isEmpty() && this.hoveredSlot != null && this.hoveredSlot.getItem().isEmpty() && this.hoveredSlot.container == menu.crafter && !isBlocked(this.hoveredSlot)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package org.violetmoon.quark.content.building.entity;

import com.mojang.authlib.GameProfile;

import net.minecraft.core.BlockPos;
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;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
Expand All @@ -31,15 +27,13 @@
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.entity.IEntityAdditionalSpawnData;
import net.minecraftforge.network.NetworkHooks;

import net.neoforged.neoforge.capabilities.BlockCapability;
import net.neoforged.neoforge.common.util.FakePlayerFactory;
import net.neoforged.neoforge.entity.IEntityWithComplexSpawn;
import net.neoforged.neoforge.items.IItemHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

import java.util.UUID;
Expand All @@ -48,6 +42,9 @@ public class GlassItemFrame extends ItemFrame implements IEntityWithComplexSpawn

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

public static final BlockCapability<IItemHandler, @Nullable Direction> ITEM_HANDLER_BLOCK =
BlockCapability.createSided(Quark.asResource("glass_frame_capability"), IItemHandler.class);

private static final String TAG_SHINY = "isShiny";
private static final GameProfile DUMMY_PROFILE = new GameProfile(UUID.randomUUID(), "ItemFrame");

Expand Down Expand Up @@ -79,16 +76,14 @@ public GlassItemFrame(Level worldIn, BlockPos blockPos, Direction face) {
@Override
public InteractionResult interact(Player player, @NotNull InteractionHand hand) {
ItemStack item = getItem();
if(!player.isShiftKeyDown() && !item.isEmpty() && !(item.getItem() instanceof BannerItem)) {
if (!player.isShiftKeyDown() && !item.isEmpty() && !(item.getItem() instanceof BannerItem)) {
BlockPos behind = getBehindPos();
BlockEntity tile = level().getBlockEntity(behind);

if(tile != null && tile.getCapability(ForgeCapabilities.ITEM_HANDLER).isPresent()) {
if(tile != null && level().getCapability(ITEM_HANDLER_BLOCK, tile.getBlockPos(), direction) != null) {
BlockState behindState = level().getBlockState(behind);
InteractionResult result = behindState.use(level(), player, hand, new BlockHitResult(new Vec3(getX(), getY(), getZ()), direction, behind, true));

if(result.consumesAction())
return result;
InteractionResult result = behindState.useWithoutItem(level(), player, new BlockHitResult(new Vec3(getX(), getY(), getZ()), direction, behind, true));
if (result.consumesAction()) return result;
}
}

Expand Down Expand Up @@ -241,12 +236,6 @@ public void readAdditionalSaveData(@NotNull CompoundTag cmp) {
entityData.set(IS_SHINY, cmp.getBoolean(TAG_SHINY));
}

@NotNull
@Override
public Packet<ClientGamePacketListener> getAddEntityPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}

@Override
public void writeSpawnData(RegistryFriendlyByteBuf registryFriendlyByteBuf) {
registryFriendlyByteBuf.writeBlockPos(this.pos);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
package org.violetmoon.quark.content.building.module;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.common.base.Functions;
import com.google.common.collect.Lists;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FlowerPotBlock;
import net.minecraft.world.level.block.state.BlockState;
import org.violetmoon.zeta.client.event.load.ZAddBlockColorHandlers;
import org.violetmoon.zeta.client.event.load.ZClientSetup;
import org.violetmoon.zeta.event.bus.LoadEvent;
import org.violetmoon.zeta.event.load.ZRegister;
import org.violetmoon.zeta.module.ZetaLoadModule;
import org.violetmoon.zeta.module.ZetaModule;
import org.violetmoon.zeta.util.Hint;

import com.google.common.base.Functions;
import com.google.common.collect.Lists;

import net.minecraft.client.Minecraft;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FlowerPotBlock;
import net.minecraft.world.level.block.state.BlockState;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@ZetaLoadModule(category = "building")
public class MorePottedPlantsModule extends ZetaModule {

private static Map<Block, Block> tintedBlocks = new HashMap<>();
private static final Map<Block, Block> tintedBlocks = new HashMap<>();

@Hint(key = "pottable_stuff")
List<Block> pottableBlocks = Lists.newArrayList();
Expand All @@ -38,7 +34,7 @@ public final void register(ZRegister event) {
add(event, Blocks.CARROTS, "carrot");
add(event, Blocks.CHORUS_FLOWER, "chorus");
add(event, Blocks.COCOA, "cocoa_bean");
Block grass = add(event, Blocks.GRASS, "grass");
Block grass = add(event, Blocks.SHORT_GRASS, "grass");
add(event, Blocks.PEONY, "peony");
Block largeFern = add(event, Blocks.LARGE_FERN, "large_fern");
add(event, Blocks.LILAC, "lilac");
Expand All @@ -59,7 +55,7 @@ public final void register(ZRegister event) {
event.getVariantRegistry().addFlowerPot(Blocks.CAVE_VINES, "cave_vines", p -> p.lightLevel(b -> 14));
add(event, Blocks.PITCHER_PLANT, "pitcher_plant");

tintedBlocks.put(grass, Blocks.GRASS);
tintedBlocks.put(grass, Blocks.SHORT_GRASS);
tintedBlocks.put(largeFern, Blocks.LARGE_FERN);
tintedBlocks.put(sugarCane, Blocks.SUGAR_CANE);
tintedBlocks.put(tallGrass, Blocks.TALL_GRASS);
Expand Down
Loading

0 comments on commit 52a86c7

Please sign in to comment.