Fix vanilla map pixel data being used in various places (#4068)
This commit is contained in:
parent
71d81cbd8d
commit
44f35fa8b1
|
@ -1,5 +1,14 @@
|
|||
--- ../src-base/minecraft/net/minecraft/client/renderer/ItemRenderer.java
|
||||
+++ ../src-work/minecraft/net/minecraft/client/renderer/ItemRenderer.java
|
||||
@@ -216,7 +216,7 @@
|
||||
bufferbuilder.func_181662_b(135.0D, -7.0D, 0.0D).func_187315_a(1.0D, 0.0D).func_181675_d();
|
||||
bufferbuilder.func_181662_b(-7.0D, -7.0D, 0.0D).func_187315_a(0.0D, 0.0D).func_181675_d();
|
||||
tessellator.func_78381_a();
|
||||
- MapData mapdata = Items.field_151098_aY.func_77873_a(p_187461_1_, this.field_78455_a.field_71441_e);
|
||||
+ MapData mapdata = ((net.minecraft.item.ItemMap) p_187461_1_.func_77973_b()).func_77873_a(p_187461_1_, this.field_78455_a.field_71441_e);
|
||||
|
||||
if (mapdata != null)
|
||||
{
|
||||
@@ -312,7 +312,7 @@
|
||||
{
|
||||
ItemStack itemstack = abstractclientplayer.func_184607_cu();
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
--- ../src-base/minecraft/net/minecraft/client/renderer/entity/RenderItemFrame.java
|
||||
+++ ../src-work/minecraft/net/minecraft/client/renderer/entity/RenderItemFrame.java
|
||||
@@ -49,7 +49,7 @@
|
||||
ModelManager modelmanager = blockrendererdispatcher.func_175023_a().func_178126_b();
|
||||
IBakedModel ibakedmodel;
|
||||
|
||||
- if (p_76986_1_.func_82335_i().func_77973_b() == Items.field_151098_aY)
|
||||
+ if (p_76986_1_.func_82335_i().func_77973_b() instanceof net.minecraft.item.ItemMap)
|
||||
{
|
||||
ibakedmodel = modelmanager.func_174953_a(this.field_177073_g);
|
||||
}
|
||||
@@ -96,10 +96,13 @@
|
||||
{
|
||||
GlStateManager.func_179094_E();
|
||||
|
@ -15,6 +24,15 @@
|
|||
if (flag)
|
||||
{
|
||||
this.field_76990_c.field_78724_e.func_110577_a(field_110789_a);
|
||||
@@ -107,7 +110,7 @@
|
||||
float f = 0.0078125F;
|
||||
GlStateManager.func_179152_a(0.0078125F, 0.0078125F, 0.0078125F);
|
||||
GlStateManager.func_179109_b(-64.0F, -64.0F, 0.0F);
|
||||
- MapData mapdata = Items.field_151098_aY.func_77873_a(itemstack, p_82402_1_.field_70170_p);
|
||||
+ MapData mapdata = ((net.minecraft.item.ItemMap) itemstack.func_77973_b()).func_77873_a(itemstack, p_82402_1_.field_70170_p);
|
||||
GlStateManager.func_179109_b(0.0F, 0.0F, -1.0F);
|
||||
|
||||
if (mapdata != null)
|
||||
@@ -124,6 +127,7 @@
|
||||
RenderHelper.func_74518_a();
|
||||
GlStateManager.func_179099_b();
|
||||
|
|
|
@ -1,5 +1,21 @@
|
|||
--- ../src-base/minecraft/net/minecraft/entity/EntityTrackerEntry.java
|
||||
+++ ../src-work/minecraft/net/minecraft/entity/EntityTrackerEntry.java
|
||||
@@ -158,13 +158,13 @@
|
||||
|
||||
if (itemstack.func_77973_b() instanceof ItemMap)
|
||||
{
|
||||
- MapData mapdata = Items.field_151098_aY.func_77873_a(itemstack, this.field_73132_a.field_70170_p);
|
||||
+ MapData mapdata = ((ItemMap) itemstack.func_77973_b()).func_77873_a(itemstack, this.field_73132_a.field_70170_p);
|
||||
|
||||
for (EntityPlayer entityplayer : p_73122_1_)
|
||||
{
|
||||
EntityPlayerMP entityplayermp = (EntityPlayerMP)entityplayer;
|
||||
mapdata.func_76191_a(entityplayermp, itemstack);
|
||||
- Packet<?> packet = Items.field_151098_aY.func_150911_c(itemstack, this.field_73132_a.field_70170_p, entityplayermp);
|
||||
+ Packet<?> packet = ((ItemMap) itemstack.func_77973_b()).func_150911_c(itemstack, this.field_73132_a.field_70170_p, entityplayermp);
|
||||
|
||||
if (packet != null)
|
||||
{
|
||||
@@ -457,6 +457,7 @@
|
||||
|
||||
this.field_73132_a.func_184178_b(p_73117_1_);
|
||||
|
|
|
@ -27,3 +27,15 @@
|
|||
{
|
||||
int i = 1 << p_77872_3_.field_76197_d;
|
||||
int j = p_77872_3_.field_76201_a;
|
||||
@@ -251,9 +251,9 @@
|
||||
|
||||
public static void func_190905_a(World p_190905_0_, ItemStack p_190905_1_)
|
||||
{
|
||||
- if (p_190905_1_.func_77973_b() == Items.field_151098_aY)
|
||||
+ if (p_190905_1_.func_77973_b() instanceof ItemMap)
|
||||
{
|
||||
- MapData mapdata = Items.field_151098_aY.func_77873_a(p_190905_1_, p_190905_0_);
|
||||
+ MapData mapdata = ((ItemMap) p_190905_1_.func_77973_b()).func_77873_a(p_190905_1_, p_190905_0_);
|
||||
|
||||
if (mapdata != null)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,249 @@
|
|||
package net.minecraftforge.debug;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.material.MapColor;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.MapItemRenderer;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemMap;
|
||||
import net.minecraft.item.ItemMapBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.play.server.SPacketMaps;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.storage.MapData;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
@Mod(modid = "mapdatatest", name = "mapdatatest", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class MapDataTest
|
||||
{
|
||||
@GameRegistry.ObjectHolder("mapdatatest:custom_map")
|
||||
public static final Item CUSTOM_MAP = null;
|
||||
|
||||
@GameRegistry.ObjectHolder("mapdatatest:empty_custom_map")
|
||||
public static final Item EMPTY_CUSTOM_MAP = null;
|
||||
|
||||
private static SimpleNetworkWrapper packetHandler;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent evt)
|
||||
{
|
||||
packetHandler = new SimpleNetworkWrapper("mapdatatest");
|
||||
packetHandler.registerMessage(CustomMapPacketHandler.class, CustomMapPacket.class, 0, Side.CLIENT);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void registerModels(ModelRegistryEvent evt)
|
||||
{
|
||||
ModelLoader.setCustomModelResourceLocation(EMPTY_CUSTOM_MAP, 0, new ModelResourceLocation("map", "inventory"));
|
||||
ModelLoader.setCustomMeshDefinition(CUSTOM_MAP, s -> new ModelResourceLocation("filled_map", "inventory"));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void registerItems(RegistryEvent.Register<Item> evt)
|
||||
{
|
||||
evt.getRegistry().register(new EmptyCustomMap().setUnlocalizedName("emptyCustomMap").setRegistryName("mapdatatest", "empty_custom_map"));
|
||||
evt.getRegistry().register(new CustomMap().setUnlocalizedName("customMap").setRegistryName("mapdatatest", "custom_map"));
|
||||
}
|
||||
|
||||
public static class EmptyCustomMap extends ItemMapBase
|
||||
{
|
||||
// copy of super, setting up our own map
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
|
||||
{
|
||||
ItemStack itemstack = CustomMap.setupNewMap(worldIn, playerIn.posX, playerIn.posZ, (byte) 0, true, false);
|
||||
ItemStack itemstack1 = playerIn.getHeldItem(handIn);
|
||||
itemstack1.shrink(1);
|
||||
|
||||
if (itemstack1.isEmpty())
|
||||
{
|
||||
return new ActionResult<>(EnumActionResult.SUCCESS, itemstack);
|
||||
} else
|
||||
{
|
||||
if (!playerIn.inventory.addItemStackToInventory(itemstack.copy()))
|
||||
{
|
||||
playerIn.dropItem(itemstack, false);
|
||||
}
|
||||
|
||||
playerIn.addStat(StatList.getObjectUseStats(this));
|
||||
return new ActionResult<>(EnumActionResult.SUCCESS, itemstack1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomMap extends ItemMap
|
||||
{
|
||||
private static final String PREFIX = "custommap";
|
||||
|
||||
// copy of super with own map prefix
|
||||
public static ItemStack setupNewMap(World worldIn, double worldX, double worldZ, byte scale, boolean trackingPosition, boolean unlimitedTracking)
|
||||
{
|
||||
ItemStack itemstack = new ItemStack(CUSTOM_MAP, 1, worldIn.getUniqueDataId(PREFIX));
|
||||
String s = PREFIX + "_" + itemstack.getMetadata();
|
||||
MapData mapdata = new CustomMapData(s);
|
||||
worldIn.setData(s, mapdata);
|
||||
mapdata.scale = scale;
|
||||
mapdata.calculateMapCenter(worldX, worldZ, mapdata.scale);
|
||||
mapdata.dimension = worldIn.provider.getDimension();
|
||||
mapdata.trackingPosition = trackingPosition;
|
||||
mapdata.unlimitedTracking = unlimitedTracking;
|
||||
mapdata.markDirty();
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
// copy of super with own map prefix and type
|
||||
@Nullable
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static CustomMapData loadMapData(int mapId, World worldIn)
|
||||
{
|
||||
String s = PREFIX + "_" + mapId;
|
||||
return (CustomMapData) worldIn.loadData(CustomMapData.class, s);
|
||||
}
|
||||
|
||||
// copy of super with own map prefix and type
|
||||
@Nullable
|
||||
@Override
|
||||
public CustomMapData getMapData(ItemStack stack, World worldIn)
|
||||
{
|
||||
String s = PREFIX + "_" + stack.getMetadata();
|
||||
CustomMapData mapdata = (CustomMapData) worldIn.loadData(CustomMapData.class, s);
|
||||
|
||||
if (mapdata == null && !worldIn.isRemote)
|
||||
{
|
||||
stack.setItemDamage(worldIn.getUniqueDataId(PREFIX));
|
||||
s = PREFIX + "_" + stack.getMetadata();
|
||||
mapdata = new CustomMapData(s);
|
||||
mapdata.scale = 3;
|
||||
mapdata.calculateMapCenter((double) worldIn.getWorldInfo().getSpawnX(), (double) worldIn.getWorldInfo().getSpawnZ(), mapdata.scale);
|
||||
mapdata.dimension = worldIn.provider.getDimension();
|
||||
mapdata.markDirty();
|
||||
worldIn.setData(s, mapdata);
|
||||
}
|
||||
|
||||
return mapdata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMapData(World worldIn, Entity viewer, MapData data)
|
||||
{
|
||||
// Solid red
|
||||
Arrays.fill(data.colors, (byte) (MapColor.RED.colorIndex * 4 + 1));
|
||||
}
|
||||
|
||||
// rewrap vanilla packet with own, to sync CustomMapData's extra data
|
||||
@Override
|
||||
public Packet<?> createMapDataPacket(ItemStack stack, World worldIn, EntityPlayer player)
|
||||
{
|
||||
SPacketMaps vanillaPacket = (SPacketMaps) super.createMapDataPacket(stack, worldIn, player);
|
||||
if (vanillaPacket == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return packetHandler.getPacketFrom(new CustomMapPacket(vanillaPacket));
|
||||
}
|
||||
}
|
||||
|
||||
// A custom subclass to distinguish from vanilla's type in the WorldSavedData
|
||||
public static class CustomMapData extends MapData
|
||||
{
|
||||
public CustomMapData(String mapname)
|
||||
{
|
||||
super(mapname);
|
||||
}
|
||||
}
|
||||
|
||||
// Custom map packet wrapping vanilla's because the handler needs to use our custom type
|
||||
public static class CustomMapPacket implements IMessage
|
||||
{
|
||||
public SPacketMaps vanillaPacket;
|
||||
|
||||
public CustomMapPacket() {}
|
||||
|
||||
public CustomMapPacket(SPacketMaps vanillaPacket)
|
||||
{
|
||||
this.vanillaPacket = vanillaPacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
vanillaPacket = new SPacketMaps();
|
||||
try {
|
||||
vanillaPacket.readPacketData(new PacketBuffer(buf));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
try {
|
||||
vanillaPacket.writePacketData(new PacketBuffer(buf));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomMapPacketHandler implements IMessageHandler<CustomMapPacket, IMessage>
|
||||
{
|
||||
@Nullable
|
||||
@Override
|
||||
public IMessage onMessage(CustomMapPacket message, MessageContext ctx) {
|
||||
// Like NetHandlerPlayClient.handleMaps but using our custom type
|
||||
Minecraft.getMinecraft().addScheduledTask(() ->
|
||||
{
|
||||
MapItemRenderer mapitemrenderer = Minecraft.getMinecraft().entityRenderer.getMapItemRenderer();
|
||||
MapData mapdata = CustomMap.loadMapData(message.vanillaPacket.getMapId(), Minecraft.getMinecraft().world);
|
||||
|
||||
if (mapdata == null) {
|
||||
String s = CustomMap.PREFIX + "_" + message.vanillaPacket.getMapId();
|
||||
mapdata = new CustomMapData(s);
|
||||
|
||||
if (mapitemrenderer.getMapInstanceIfExists(s) != null) {
|
||||
MapData mapdata1 = mapitemrenderer.getData(mapitemrenderer.getMapInstanceIfExists(s));
|
||||
|
||||
if (mapdata1 != null) {
|
||||
mapdata = mapdata1;
|
||||
}
|
||||
}
|
||||
|
||||
Minecraft.getMinecraft().world.setData(s, mapdata);
|
||||
}
|
||||
|
||||
message.vanillaPacket.setMapdataTo(mapdata);
|
||||
mapitemrenderer.updateMapTexture(mapdata);
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue