mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-27 01:14:46 +00:00
Replace reflection with access transformers
This makes the code slightly neater and allows us to catch places where the variable/function has been renamed between versions.
This commit is contained in:
parent
2fd01b2adf
commit
63cdc7a72e
@ -63,6 +63,12 @@ dependencies {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
manifest {
|
||||||
|
attributes('FMLAT': 'computercraft_at.cfg')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
processResources
|
processResources
|
||||||
{
|
{
|
||||||
// this will ensure that this task is redone when the versions change.
|
// this will ensure that this task is redone when the versions change.
|
||||||
|
@ -134,7 +134,7 @@ public abstract class BlockGeneric extends Block implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final ItemStack createStackedBlock( @Nonnull IBlockState state )
|
public final ItemStack createStackedBlock( @Nonnull IBlockState state )
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import net.minecraft.item.ItemRecord;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.SoundEvent;
|
import net.minecraft.util.SoundEvent;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@ -46,7 +45,7 @@ public class RecordMedia implements IMedia
|
|||||||
public SoundEvent getAudio( @Nonnull ItemStack stack )
|
public SoundEvent getAudio( @Nonnull ItemStack stack )
|
||||||
{
|
{
|
||||||
ItemRecord itemRecord = (ItemRecord)stack.getItem();
|
ItemRecord itemRecord = (ItemRecord)stack.getItem();
|
||||||
return ObfuscationReflectionHelper.getPrivateValue(ItemRecord.class, itemRecord, "field_185076_b");
|
return itemRecord.sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,7 +38,6 @@ import net.minecraft.tileentity.TileEntity;
|
|||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
||||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
|
||||||
import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent;
|
import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.registry.EntityRegistry;
|
import net.minecraftforge.fml.common.registry.EntityRegistry;
|
||||||
@ -180,26 +179,12 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
|||||||
{
|
{
|
||||||
if( !m_dropConsumers.containsKey( entity ) )
|
if( !m_dropConsumers.containsKey( entity ) )
|
||||||
{
|
{
|
||||||
boolean captured = ObfuscationReflectionHelper.<Boolean, Entity>getPrivateValue(
|
boolean captured = entity.captureDrops;
|
||||||
Entity.class,
|
|
||||||
entity,
|
|
||||||
"captureDrops"
|
|
||||||
);
|
|
||||||
|
|
||||||
if( !captured )
|
if( !captured )
|
||||||
{
|
{
|
||||||
ObfuscationReflectionHelper.setPrivateValue(
|
entity.captureDrops = true;
|
||||||
Entity.class,
|
ArrayList<EntityItem> items = entity.capturedDrops;
|
||||||
entity,
|
|
||||||
Boolean.TRUE,
|
|
||||||
"captureDrops"
|
|
||||||
);
|
|
||||||
|
|
||||||
ArrayList<EntityItem> items = ObfuscationReflectionHelper.getPrivateValue(
|
|
||||||
Entity.class,
|
|
||||||
entity,
|
|
||||||
"capturedDrops"
|
|
||||||
);
|
|
||||||
|
|
||||||
if( items == null || items.size() == 0 )
|
if( items == null || items.size() == 0 )
|
||||||
{
|
{
|
||||||
@ -214,26 +199,12 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
|
|||||||
{
|
{
|
||||||
if( m_dropConsumers.containsKey( entity ) )
|
if( m_dropConsumers.containsKey( entity ) )
|
||||||
{
|
{
|
||||||
boolean captured = ObfuscationReflectionHelper.<Boolean, Entity>getPrivateValue(
|
boolean captured = entity.captureDrops;
|
||||||
Entity.class,
|
|
||||||
entity,
|
|
||||||
"captureDrops"
|
|
||||||
);
|
|
||||||
|
|
||||||
if( captured )
|
if( captured )
|
||||||
{
|
{
|
||||||
ObfuscationReflectionHelper.setPrivateValue(
|
entity.captureDrops = false;
|
||||||
Entity.class,
|
ArrayList<EntityItem> items = entity.capturedDrops;
|
||||||
entity,
|
|
||||||
Boolean.FALSE,
|
|
||||||
"captureDrops"
|
|
||||||
);
|
|
||||||
|
|
||||||
ArrayList<EntityItem> items = ObfuscationReflectionHelper.getPrivateValue(
|
|
||||||
Entity.class,
|
|
||||||
entity,
|
|
||||||
"capturedDrops"
|
|
||||||
);
|
|
||||||
|
|
||||||
if( items != null )
|
if( items != null )
|
||||||
{
|
{
|
||||||
|
@ -73,7 +73,6 @@ import net.minecraft.world.World;
|
|||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.world.WorldEvent;
|
import net.minecraftforge.event.world.WorldEvent;
|
||||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
|
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
|
||||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
|
||||||
import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent;
|
import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||||
@ -130,8 +129,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
|
|||||||
if (item instanceof ItemRecord)
|
if (item instanceof ItemRecord)
|
||||||
{
|
{
|
||||||
ItemRecord record = (ItemRecord) item;
|
ItemRecord record = (ItemRecord) item;
|
||||||
String key = ObfuscationReflectionHelper.getPrivateValue( ItemRecord.class, record, "field_185077_c" );
|
return StringUtil.translateToLocal( record.displayName );
|
||||||
return StringUtil.translateToLocal( key );
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,8 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
public class TurtleCompareCommand implements ITurtleCommand
|
public class TurtleCompareCommand implements ITurtleCommand
|
||||||
{
|
{
|
||||||
@ -58,22 +56,7 @@ public class TurtleCompareCommand implements ITurtleCommand
|
|||||||
// Try createStackedBlock first
|
// Try createStackedBlock first
|
||||||
if( !lookAtBlock.hasTileEntity( lookAtState ) )
|
if( !lookAtBlock.hasTileEntity( lookAtState ) )
|
||||||
{
|
{
|
||||||
try
|
lookAtStack = lookAtBlock.createStackedBlock( lookAtState );
|
||||||
{
|
|
||||||
Method method = ReflectionHelper.findMethod(
|
|
||||||
Block.class, lookAtBlock,
|
|
||||||
new String[]{ "func_149644_j", "j", "createStackedBlock" },
|
|
||||||
IBlockState.class
|
|
||||||
);
|
|
||||||
if( method != null )
|
|
||||||
{
|
|
||||||
lookAtStack = (ItemStack)method.invoke( lookAtBlock, lookAtState );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
// ???
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if the block drops anything with the same ID as itself
|
// See if the block drops anything with the same ID as itself
|
||||||
|
6
src/main/resources/META-INF/computercraft_at.cfg
Normal file
6
src/main/resources/META-INF/computercraft_at.cfg
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# RecordMedia (and related methods)
|
||||||
|
public net.minecraft.item.ItemRecord field_185076_b # sound
|
||||||
|
public net.minecraft.item.ItemRecord field_185077_c # displayName
|
||||||
|
|
||||||
|
# TurtleCompareCommand
|
||||||
|
public net.minecraft.block.Block func_180643_i(Lnet/minecraft/block/state/IBlockState;)Lnet/minecraft/item/ItemStack; # createStackedBlock
|
Loading…
Reference in New Issue
Block a user