Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
First pass with splitting and cleanup of mixins. Some mixins were out…
Browse files Browse the repository at this point in the history
…dated....

Signed-off-by: Gabriel Harris-Rouquette <[email protected]>
  • Loading branch information
gabizou committed Jun 11, 2019
1 parent 00d93d5 commit bb6a6a4
Show file tree
Hide file tree
Showing 26 changed files with 299 additions and 406 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ Thumbs.db
.settings
.checkstyle
.factorypath
run
./eclipse
*/eclipse
nbproject
atlassian-ide-plugin.xml
build.xml
Expand All @@ -76,3 +75,5 @@ nb-configuration.xml
/.apt_generated/
*.launch
classes/
# Ignore mixin generated folders. these contain compiled class transformed classes and potentially generated sourcecode.
.mixin.out/
2 changes: 1 addition & 1 deletion SpongeCommon
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import net.minecraftforge.event.world.ChunkWatchEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.spongepowered.common.interfaces.IMixinChunk;
import org.spongepowered.common.interfaces.entity.IMixinEntity;
import org.spongepowered.common.bridge.entity.IMixinEntity;
import org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer;
import org.spongepowered.common.util.SpongeHooks;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ private static void handleCustomStack(SpawnEntityEvent event) {
}

private static void handleCustomEntityFromIterator(ListIterator<org.spongepowered.api.entity.Entity> it, Entity entity) {
final ItemStack stack = EntityUtil.getItem(entity);
final ItemStack stack = entity instanceof EntityItem ? ((EntityItem) entity).getItem() : ItemStack.EMPTY;
final Item item = stack.getItem();

if (item.hasCustomEntity(stack)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.common.entity.PlayerTracker;
import org.spongepowered.common.interfaces.IMixinChunk;
import org.spongepowered.common.interfaces.entity.IMixinEntity;
import org.spongepowered.common.bridge.entity.IMixinEntity;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@
*/
package org.spongepowered.mod.mixin.core.common;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Streams;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.crash.CrashReport;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
Expand All @@ -44,6 +47,7 @@
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
Expand All @@ -63,6 +67,7 @@
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.ForgeModContainer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.CapabilityDispatcher;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
Expand All @@ -76,8 +81,11 @@
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.tileentity.TileEntityType;
import org.spongepowered.api.command.args.ChildCommandElementExecutor;
import org.spongepowered.api.data.DataContainer;
import org.spongepowered.api.data.type.Profession;
import org.spongepowered.api.event.block.InteractBlockEvent;
import org.spongepowered.api.item.ItemType;
import org.spongepowered.api.item.ItemTypes;
import org.spongepowered.api.item.inventory.Inventory;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.crafting.CraftingGridInventory;
Expand All @@ -89,6 +97,9 @@
import org.spongepowered.common.SpongeImpl;
import org.spongepowered.common.SpongeImplHooks;
import org.spongepowered.common.command.SpongeCommandFactory;
import org.spongepowered.common.data.persistence.NbtTranslator;
import org.spongepowered.common.data.util.DataQueries;
import org.spongepowered.common.data.util.NbtDataUtil;
import org.spongepowered.common.entity.EntityUtil;
import org.spongepowered.common.entity.SpongeProfession;
import org.spongepowered.common.event.tracking.PhaseContext;
Expand All @@ -101,6 +112,7 @@
import org.spongepowered.common.interfaces.world.IMixinITeleporter;
import org.spongepowered.common.item.inventory.util.InventoryUtil;
import org.spongepowered.common.item.inventory.util.ItemStackUtil;
import org.spongepowered.common.registry.type.ItemTypeRegistryModule;
import org.spongepowered.common.registry.type.block.TileEntityTypeRegistryModule;
import org.spongepowered.common.registry.type.entity.ProfessionRegistryModule;
import org.spongepowered.common.registry.type.world.PortalAgentRegistryModule;
Expand All @@ -114,6 +126,7 @@
import org.spongepowered.mod.interfaces.IMixinVillagerProfession;
import org.spongepowered.mod.item.inventory.adapter.IItemHandlerAdapter;
import org.spongepowered.mod.mixin.core.forge.IMixinVillagerRegistry;
import org.spongepowered.mod.mixin.core.item.AccessorForgeItemStack;
import org.spongepowered.mod.plugin.SpongeModPluginContainer;
import org.spongepowered.mod.util.StaticMixinForgeHelper;
import org.spongepowered.mod.util.WrappedArrayList;
Expand Down Expand Up @@ -956,9 +969,11 @@ public static EnumActionResult onForgeItemUseFirst(EntityPlayer player, net.mine
* @param entity The vanilla entity item
* @return The custom item entity for the dropped item
*/
@Nullable
@Overwrite
public static Entity getCustomEntityIfItem(Entity entity) {
final net.minecraft.item.ItemStack stack = EntityUtil.getItem(entity);
final net.minecraft.item.ItemStack stack =
entity instanceof EntityItem ? ((EntityItem) entity).getItem() : net.minecraft.item.ItemStack.EMPTY;
final Item item = stack.getItem();

if (item.hasCustomEntity(stack)) {
Expand All @@ -972,4 +987,86 @@ public static Entity getCustomEntityIfItem(Entity entity) {
return entity;
}

/**
* @author gabizou - June 10th, 2019 - 1.12.2
* @reason Forge supports replacing registry entries,
* and for Items, that's being done pretty much by half the
* larger library mods out there.
*
* @param mixinItem_api The item
* @return The resource location
*/
@Overwrite
@Nullable
public static ResourceLocation getItemResourceLocation(Item mixinItem_api) {
return mixinItem_api.getRegistryName();
}

/**
* @author gabizou - June 10th, 2019 - 1.12.2
* @reason Forge supports item registration replacements, we have to abide
* by that.
*
* @param id The numerical id
* @param name The item name/id being registered to like "minecraft:diamond_sword"
* @param item The item
*/
@Overwrite
public static void registerItemForSpongeRegistry(int id, ResourceLocation name, Item item) {
final Item registered;
final ResourceLocation nameForObject = Item.REGISTRY.getNameForObject(item);
if (nameForObject == null) {
registered = checkNotNull(Item.REGISTRY.getObject(name), "Someone replaced a vanilla item with a null item!!!");
} else {
registered = item;
}
ItemTypeRegistryModule.getInstance().registerAdditionalCatalog((ItemType) registered);
}

/**
* @author gabizou - June 10th, 2019
* @reason Access forge capabilities to write to DataView
* for the implementation of {@link ItemStack#toContainer()}.
*/
@SuppressWarnings("ConstantConditions")
@Overwrite
public static void writeItemStackCapabilitiesToDataView(DataContainer container, net.minecraft.item.ItemStack stack) {
final CapabilityDispatcher capabilities = ((AccessorForgeItemStack) (Object) stack).accessor$getCapabilities();
if (capabilities != null) {
final NBTTagCompound caps = capabilities.serializeNBT();
if (caps != null && !caps.isEmpty()) {
final DataContainer capsView = NbtTranslator.getInstance().translate(caps);
container.set(DataQueries.UNSAFE_NBT.then(NbtDataUtil.FORGE_CAPS), capsView);
}
}
}

/**
* @author gabizou - June 10th, 2019
* @reason Forge adds some changes to allow enchantments on items or books.
*
* @param enchantment The enchantment
* @param stack The item stack
* @return True if it can be applied
*/
@Overwrite
public static boolean canEnchantmentBeAppliedToItem(Enchantment enchantment, net.minecraft.item.ItemStack stack) {
return (stack.getItem() == ItemTypes.BOOK) ? enchantment.isAllowedOnBooks() : enchantment.canApply((net.minecraft.item.ItemStack) (Object) stack);
}

/**
* @author gabizou - June 10th, 2019
* @reason Forge adds capabilities and we need to deserialize them
* from the compound.
*
* @param stack The item stack
* @param compoundTag The compound tag
*/
@Overwrite
public static void setCapabilitiesFromSpongeBuilder(ItemStack stack, NBTTagCompound compoundTag) {
final CapabilityDispatcher capabilities = ((AccessorForgeItemStack) stack).accessor$getCapabilities();
if (capabilities != null) {
capabilities.deserializeNBT(compoundTag);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.common.entity.EntityUtil;
import org.spongepowered.common.interfaces.entity.IMixinEntity;
import org.spongepowered.common.bridge.entity.IMixinEntity;
import org.spongepowered.common.interfaces.world.IMixinITeleporter;
import org.spongepowered.mod.util.WrappedArrayList;

Expand Down Expand Up @@ -65,7 +65,7 @@ public abstract class MixinEntity implements IMixinEntity {
public net.minecraft.entity.Entity changeDimension(int toDimensionId, ITeleporter teleporter) {
if (!this.world.isRemote && !this.isDead) {
// Sponge Start - Handle teleportation solely in TrackingUtil where everything can be debugged.
return EntityUtil.transferEntityToDimension(this, toDimensionId, (IMixinITeleporter) teleporter, null);
return EntityUtil.transferEntityToDimension((Entity) (Object) this, toDimensionId, (IMixinITeleporter) teleporter, null);
// Sponge End
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.mod.mixin.core.item.inventory;
package org.spongepowered.mod.mixin.core.forge.items;

import net.minecraftforge.items.ItemStackHandler;
import org.spongepowered.api.item.inventory.EmptyInventory;
Expand Down Expand Up @@ -51,7 +51,7 @@
@SuppressWarnings("rawtypes")
@Mixin(ItemStackHandler.class)
@Implements(@Interface(iface = Inventory.class, prefix = "inventory$"))
public abstract class MixinItemStackHandler implements MinecraftInventoryAdapter, IMixinInventory {
public abstract class MixinItemStackHandler_Forge implements MinecraftInventoryAdapter, IMixinInventory {

@Nullable protected Inventory parent;
protected SlotCollection slots;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.mod.mixin.core.item.inventory;
package org.spongepowered.mod.mixin.core.forge.items;

import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;
import org.spongepowered.api.item.inventory.Inventory;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.common.mixin.core.item.inventory.MixinSlot;
import org.spongepowered.common.mixin.core.inventory.MixinSlot;
import org.spongepowered.mod.item.inventory.adapter.IItemHandlerAdapter;

@Mixin(value = SlotItemHandler.class, remap = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.mod.mixin.core.item.inventory;
package org.spongepowered.mod.mixin.core.forge.items.wrapper;

import net.minecraftforge.items.wrapper.InvWrapper;
import org.spongepowered.api.item.inventory.EmptyInventory;
Expand Down Expand Up @@ -51,7 +51,7 @@
@SuppressWarnings("rawtypes")
@Mixin(InvWrapper.class)
@Implements(@Interface(iface = Inventory.class, prefix = "inventory$"))
public abstract class MixinInvWrapper implements MinecraftInventoryAdapter, IMixinInventory {
public abstract class MixinInvWrapper_Forge implements MinecraftInventoryAdapter, IMixinInventory {

@Nullable protected Inventory parent;
protected SlotCollection slots;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.spongepowered.mod.mixin.core.item;

import net.minecraft.item.ItemStack;
import net.minecraftforge.common.capabilities.CapabilityDispatcher;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import javax.annotation.Nullable;

@Mixin(ItemStack.class)
public interface AccessorForgeItemStack {

@Nullable
@Accessor(value = "capabilities", remap = false)
CapabilityDispatcher accessor$getCapabilities();

}

This file was deleted.

Loading

0 comments on commit bb6a6a4

Please sign in to comment.