Skip to content

Commit

Permalink
Merge pull request #816 from TheidenHD/master
Browse files Browse the repository at this point in the history
Backport 1.20 fixes
  • Loading branch information
Dudblockman authored Jan 10, 2025
2 parents 8bcd7ac + a4cb44c commit 088852e
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 104 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mapping_channel=parchment
mod_id=psi
forge_version=43.3.0
jei_version=11.6.0.1013
build_number=101
build_number=102
patchy_version=1.19.2-77
dir_output=../Build Output/Psi/
version=1.19
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/vazkii/psi/api/PsiAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.ForgeTier;
import net.minecraftforge.common.TierSortingRegistry;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.CapabilityToken;
Expand All @@ -35,14 +40,15 @@
import vazkii.psi.api.internal.DummyMethodHandler;
import vazkii.psi.api.internal.IInternalMethodHandler;
import vazkii.psi.api.material.PsimetalArmorMaterial;
import vazkii.psi.api.material.PsimetalToolMaterial;
import vazkii.psi.api.spell.ISpellAcceptor;
import vazkii.psi.api.spell.ISpellImmune;
import vazkii.psi.api.spell.SpellPiece;
import vazkii.psi.api.spell.detonator.IDetonationHandler;
import vazkii.psi.common.item.base.ModItems;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -81,7 +87,11 @@ public final class PsiAPI {

public static final PsimetalArmorMaterial PSIMETAL_ARMOR_MATERIAL = new PsimetalArmorMaterial("psimetal", 18, new int[] { 2, 5, 6, 2 },
12, SoundEvents.ARMOR_EQUIP_IRON, 0F, () -> Ingredient.of(Registry.ITEM.get(new ResourceLocation(MOD_ID, "psimetal"))), 0.0f);
public static final PsimetalToolMaterial PSIMETAL_TOOL_MATERIAL = new PsimetalToolMaterial();
public static final Tier PSIMETAL_TOOL_MATERIAL = TierSortingRegistry.registerTier(
new ForgeTier(3, 900, 7.8F, 2F, 12, BlockTags.NEEDS_DIAMOND_TOOL, () -> Ingredient.of(ModItems.psimetal)),
new ResourceLocation(MOD_ID, "psimetal_tier"),
List.of(Tiers.DIAMOND), List.of(Tiers.NETHERITE));


/**
* Registers a Spell Piece.
Expand Down
52 changes: 0 additions & 52 deletions src/main/java/vazkii/psi/api/material/PsimetalToolMaterial.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
}

public int getPageCount() {
return (visibleButtons.size() / PIECES_PER_PAGE) + 1;
return (int) Math.ceil((float) visibleButtons.size() / PIECES_PER_PAGE);
}

public void populatePanelButtons() {
Expand Down
81 changes: 49 additions & 32 deletions src/main/java/vazkii/psi/common/block/tile/TileCADAssembler.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,8 @@ public class TileCADAssembler extends BlockEntity implements ITileCADAssembler,
@ObjectHolder(registryName = "minecraft:block_entity_type", value = LibMisc.PREFIX_MOD + LibBlockNames.CAD_ASSEMBLER)
public static BlockEntityType<TileCADAssembler> TYPE;

private final IItemHandlerModifiable inventory = new ItemStackHandler(6) {
@Override
protected void onContentsChanged(int slot) {
super.onContentsChanged(slot);
if(0 < slot && slot < 6) {
clearCachedCAD();
}
}
private final CADStackHandler inventory = new CADStackHandler(6);

@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
if(stack.isEmpty()) {
return true;
}

if(slot == 0) {
return ISocketable.isSocketable(stack);
} else if(slot < 6) {
return stack.getItem() instanceof ICADComponent &&
((ICADComponent) stack.getItem()).getComponentType(stack) == EnumCADComponent.values()[slot - 1];
}

return false;
}
};
private final IItemHandler publicInv = new IItemHandler() {
@Override
public int getSlots() {
Expand Down Expand Up @@ -237,11 +214,7 @@ public boolean isBulletSlotEnabled(int slot) {
@Override
protected void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag);
NonNullList<ItemStack> items = NonNullList.withSize(inventory.getSlots(), ItemStack.EMPTY);
for(int i = 0; i < inventory.getSlots(); i++) {
items.set(i, inventory.getStackInSlot(i));
}
ContainerHelper.saveAllItems(tag, items);
ContainerHelper.saveAllItems(tag, inventory.getItems());
}

@Override
Expand All @@ -250,10 +223,13 @@ public void load(CompoundTag cmp) {
readPacketNBT(cmp);
}



public void readPacketNBT(@Nonnull CompoundTag tag) {
// Migrate old CAD assemblers to the new format
if(tag.getInt("version") < 1) {
ListTag items = tag.getList("Items", 10);
ListTag items = tag.getList("Items", 10);
if(items.size() == 19) {

for(int i = 0; i < inventory.getSlots(); i++) {
inventory.setStackInSlot(i, ItemStack.EMPTY);
}
Expand Down Expand Up @@ -295,7 +271,7 @@ public void readPacketNBT(@Nonnull CompoundTag tag) {
}
}
} else {
//CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(inventory, null, tag.getList("Items", Tag.TAG_COMPOUND)); //TODO Fix this but we need answers
ContainerHelper.loadAllItems(tag, inventory.getItems());
}
}

Expand Down Expand Up @@ -324,4 +300,45 @@ public Component getDisplayName() {
public AbstractContainerMenu createMenu(int i, Inventory playerInventory, Player playerEntity) {
return new ContainerCADAssembler(i, playerInventory, this);
}

private class CADStackHandler extends ItemStackHandler {


private CADStackHandler(int size) {
super(size);
}

private NonNullList<ItemStack> getItems() {
return this.stacks;
}

private void setItems(NonNullList<ItemStack> pItems) {
this.stacks = pItems;
}

@Override
protected void onContentsChanged(int slot) {
super.onContentsChanged(slot);
if (0 < slot && slot < 6) {
clearCachedCAD();
}
setChanged();
}

@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
if (stack.isEmpty()) {
return true;
}

if (slot == 0) {
return ISocketable.isSocketable(stack);
} else if (slot < 6) {
return stack.getItem() instanceof ICADComponent &&
((ICADComponent) stack.getItem()).getComponentType(stack).ordinal() == slot - 1;
}

return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public ItemStack quickMoveStack(Player playerIn, int from) {

@Override
public void removed(Player playerIn) {
super.removed(playerIn);
assembler.clearCachedCAD();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static void onPlayerTick(TickEvent.LevelTickEvent e) {
//Otherwise it feels jerky.
if(entity instanceof ServerPlayer) {
MessageRegister.sendToPlayer(motion, (ServerPlayer) entity);
((ServerPlayer) entity).connection.aboveGroundTickCount = -80; //Improve "Kicked for Flying"
} else {
entity.push(vec.x, vec.y, vec.z);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static boolean isContributor(String name) {

@SubscribeEvent
public static void onCadTake(CADTakeEvent event) {
if(ContributorSpellCircleHandler.isContributor(event.getPlayer().getName().getString().toLowerCase(Locale.ROOT)) && !((ICAD) event.getCad().getItem()).getComponentInSlot(event.getCad(), EnumCADComponent.DYE).isEmpty()) {
if(ContributorSpellCircleHandler.isContributor(event.getPlayer().getName().getString().toLowerCase(Locale.ROOT)) && !event.getCad().isEmpty() && !((ICAD) event.getCad().getItem()).getComponentInSlot(event.getCad(), EnumCADComponent.DYE).isEmpty()) {
ItemStack dyeStack = ((ICAD) event.getCad().getItem()).getComponentInSlot(event.getCad(), EnumCADComponent.DYE);
((ICADColorizer) dyeStack.getItem()).setContributorName(dyeStack, event.getPlayer().getName().getString());
ItemCAD.setComponent(event.getCad(), dyeStack);
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/vazkii/psi/common/item/ItemVectorRuler.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ public InteractionResult useOn(UseOnContext ctx) {
BlockPos pos = ctx.getClickedPos();

ItemStack stack = ctx.getPlayer().getItemInHand(ctx.getHand());
int srcY = stack.getOrCreateTag().contains(TAG_SRC_Y) ? stack.getOrCreateTag().getInt(TAG_SRC_Y) : -1;

if(srcY == -1 || ctx.getPlayer().isShiftKeyDown()) {
if(!stack.getOrCreateTag().contains(TAG_SRC_Y) || ctx.getPlayer().isShiftKeyDown()) {
stack.getOrCreateTag().putInt(TAG_SRC_X, pos.getX());
stack.getOrCreateTag().putInt(TAG_SRC_Y, pos.getY());
stack.getOrCreateTag().putInt(TAG_SRC_Z, pos.getZ());
stack.getOrCreateTag().putInt(TAG_DST_Y, -1);
stack.removeTagKey(TAG_DST_Y);
} else {
stack.getOrCreateTag().putInt(TAG_DST_X, pos.getX());
stack.getOrCreateTag().putInt(TAG_DST_Y, pos.getY());
Expand All @@ -77,12 +76,12 @@ public Vector3 getVector(ItemStack stack) {
int srcY = stack.getOrCreateTag().getInt(TAG_SRC_Y);
int srcZ = stack.getOrCreateTag().getInt(TAG_SRC_Z);

int dstY = stack.getOrCreateTag().contains(TAG_DST_Y) ? stack.getOrCreateTag().getInt(TAG_DST_Y) : -1;
if(dstY == -1) {
if(!stack.getOrCreateTag().contains(TAG_DST_Y)) {
return new Vector3(srcX, srcY, srcZ);
}

int dstX = stack.getOrCreateTag().getInt(TAG_DST_X);
int dstY = stack.getOrCreateTag().getInt(TAG_DST_Y);
int dstZ = stack.getOrCreateTag().getInt(TAG_DST_Z);

return new Vector3(dstX - srcX, dstY - srcY, dstZ - srcZ);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ public int getColor(@Nonnull ItemStack stack) {
return ICADColorizer.DEFAULT_SPELL_COLOR;
}

public void setColor(ItemStack stack, int color) {
}

@Override
public void initializeClient(Consumer<IClientItemExtensions> consumer) {
consumer.accept(new IClientItemExtensions() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public net.minecraft.client.gui.Gui f_92986_ # minecraft
public net.minecraft.client.gui.components.ChatComponent m_93787_(Lnet/minecraft/network/chat/Component;I)V # addMessage
public net.minecraft.client.gui.components.ChatComponent m_93803_(I)V # removeById
public net.minecraft.client.renderer.RenderType$CompositeRenderType
public net.minecraft.client.renderer.RenderStateShard f_173101_ # POSITION_COLOR_TEX_SHADER
public net.minecraft.client.renderer.RenderStateShard f_173101_ # POSITION_COLOR_TEX_SHADER
public net.minecraft.server.network.ServerGamePacketListenerImpl f_9737_ # floatingTickCount
25 changes: 16 additions & 9 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,30 @@ issueTrackerURL="https://github.com/Vazkii/Psi"
license="https://psi.vazkii.net/license.php"

[[mods]]
modId="psi"
displayName="Psi"
version="2.0.0"
authors="Vazkii, Wiiv, WireSegal, Kamefrede, Williewillus, Hubry, Dudblockman"
description='''
Psionic Spellcasting Instruments
'''
modId="psi"
displayName="Psi"
version="2.0.0"
authors="Vazkii, Wiiv, WireSegal, Kamefrede, Williewillus, Hubry, Dudblockman"
description='''
Psionic Spellcasting Instruments
'''

[[dependencies.psi]]
modId="patchouli"
mandatory=true
versionRange="[1.19.2-77,)"
side="BOTH"


[[dependencies.psi]]
modId="forge"
mandatory=true
versionRange="[42.2.0,)"
versionRange="[43.3.0,)"
ordering="AFTER"
side="BOTH"

[[dependencies.psi]]
modId="minecraft"
mandatory=true
versionRange="[1.19,1.19.2]"
ordering="NONE"
side="BOTH"

0 comments on commit 088852e

Please sign in to comment.