Fix remaining issues preventing compilation, launching, and loading worlds (#5156)

Fix duplicate ID for ingredient serializers
Fix KeyBinding compile errors. No GuiKeyBindingList patches yet.
Implement controls GUI and WorldServer patches
This commit is contained in:
tterrag authored and LexManos committed 2018-09-21 19:07:48 -07:00
1 parent c191851ec0
commit d08f8e1a78
15 files changed
+645 -75

No files matched your search

@@ -0,0 +1,53 @@
package net.minecraftforge.client.extensions;
import javax.annotation.Nonnull;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.client.util.InputMappings;
import net.minecraftforge.client.settings.IKeyConflictContext;
import net.minecraftforge.client.settings.KeyModifier;
public interface IForgeKeybinding
{
default KeyBinding getKeyBinding() { return (KeyBinding) this; }
@Nonnull InputMappings.Input getKey();
/**
* Checks that the key conflict context and modifier are active, and that the keyCode matches this binding.
*/
default boolean isActiveAndMatches(InputMappings.Input keyCode)
{
return keyCode.func_197937_c() != 0 && keyCode.equals(getKey()) && getKeyConflictContext().isActive() && getKeyModifier().isActive(getKeyConflictContext());
}
default void setToDefault()
{
setKeyModifierAndCode(getKeyModifierDefault(), getKeyBinding().func_197977_i());
}
void setKeyConflictContext(IKeyConflictContext keyConflictContext);
IKeyConflictContext getKeyConflictContext();
KeyModifier getKeyModifierDefault();
KeyModifier getKeyModifier();
void setKeyModifierAndCode(KeyModifier keyModifier, InputMappings.Input keyCode);
/**
* Returns true when one of the bindings' key codes conflicts with the other's modifier.
*/
default boolean hasKeyCodeModifierConflict(KeyBinding other)
{
if (getKeyConflictContext().conflicts(other.getKeyConflictContext()) || other.getKeyConflictContext().conflicts(getKeyConflictContext()))
{
if (getKeyModifier().matches(other.getKey()) || other.getKeyModifier().matches(getKey()))
{
return true;
}
}
return false;
}
}
@@ -20,27 +20,30 @@
package net.minecraftforge.client.settings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.client.util.InputMappings;
import net.minecraft.util.IntHashMap;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class KeyBindingMap
{
private static final EnumMap<KeyModifier, IntHashMap<Collection<KeyBinding>>> map = new java.util.EnumMap<KeyModifier, IntHashMap<Collection<KeyBinding>>>(KeyModifier.class);
private static final EnumMap<KeyModifier, Map<InputMappings.Input, Collection<KeyBinding>>> map = new EnumMap<>(KeyModifier.class);
static
{
for (KeyModifier modifier : KeyModifier.values())
{
map.put(modifier, new IntHashMap<Collection<KeyBinding>>());
map.put(modifier, new HashMap<>());
}
}
@Nullable
public KeyBinding lookupActive(int keyCode)
public KeyBinding lookupActive(InputMappings.Input keyCode)
{
KeyModifier activeModifier = KeyModifier.getActiveModifier();
if (!activeModifier.matches(keyCode))
@@ -55,9 +58,9 @@ public class KeyBindingMap
}
@Nullable
private KeyBinding getBinding(int keyCode, KeyModifier keyModifier)
private KeyBinding getBinding(InputMappings.Input keyCode, KeyModifier keyModifier)
{
Collection<KeyBinding> bindings = map.get(keyModifier).lookup(keyCode);
Collection<KeyBinding> bindings = map.get(keyModifier).get(keyCode);
if (bindings != null)
{
for (KeyBinding binding : bindings)
@@ -71,12 +74,12 @@ public class KeyBindingMap
return null;
}
public List<KeyBinding> lookupAll(int keyCode)
public List<KeyBinding> lookupAll(InputMappings.Input keyCode)
{
List<KeyBinding> matchingBindings = new ArrayList<KeyBinding>();
for (IntHashMap<Collection<KeyBinding>> bindingsMap : map.values())
for (Map<InputMappings.Input, Collection<KeyBinding>> bindingsMap : map.values())
{
Collection<KeyBinding> bindings = bindingsMap.lookup(keyCode);
Collection<KeyBinding> bindings = bindingsMap.get(keyCode);
if (bindings != null)
{
matchingBindings.addAll(bindings);
@@ -85,15 +88,15 @@ public class KeyBindingMap
return matchingBindings;
}
public void addKey(int keyCode, KeyBinding keyBinding)
public void addKey(InputMappings.Input keyCode, KeyBinding keyBinding)
{
KeyModifier keyModifier = keyBinding.getKeyModifier();
IntHashMap<Collection<KeyBinding>> bindingsMap = map.get(keyModifier);
Collection<KeyBinding> bindingsForKey = bindingsMap.lookup(keyCode);
Map<InputMappings.Input, Collection<KeyBinding>> bindingsMap = map.get(keyModifier);
Collection<KeyBinding> bindingsForKey = bindingsMap.get(keyCode);
if (bindingsForKey == null)
{
bindingsForKey = new ArrayList<KeyBinding>();
bindingsMap.addKey(keyCode, bindingsForKey);
bindingsMap.put(keyCode, bindingsForKey);
}
bindingsForKey.add(keyBinding);
}
@@ -101,24 +104,24 @@ public class KeyBindingMap
public void removeKey(KeyBinding keyBinding)
{
KeyModifier keyModifier = keyBinding.getKeyModifier();
int keyCode = keyBinding.getKeyCode();
IntHashMap<Collection<KeyBinding>> bindingsMap = map.get(keyModifier);
Collection<KeyBinding> bindingsForKey = bindingsMap.lookup(keyCode);
InputMappings.Input keyCode = keyBinding.getKey();
Map<InputMappings.Input, Collection<KeyBinding>> bindingsMap = map.get(keyModifier);
Collection<KeyBinding> bindingsForKey = bindingsMap.get(keyCode);
if (bindingsForKey != null)
{
bindingsForKey.remove(keyBinding);
if (bindingsForKey.isEmpty())
{
bindingsMap.removeObject(keyCode);
bindingsMap.remove(keyCode);
}
}
}
public void clearMap()
{
for (IntHashMap<Collection<KeyBinding>> bindings : map.values())
for (Map<InputMappings.Input, Collection<KeyBinding>> bindings : map.values())
{
bindings.clearMap();
bindings.clear();
}
}
}
@@ -21,18 +21,19 @@ package net.minecraftforge.client.settings;
import javax.annotation.Nullable;
import net.minecraft.client.GameSettings;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.InputMappings;
import org.lwjgl.glfw.GLFW;
public enum KeyModifier {
CONTROL {
@Override
public boolean matches(int keyCode)
public boolean matches(InputMappings.Input key)
{
int keyCode = key.func_197937_c();
if (Minecraft.IS_RUNNING_ON_MAC)
{
return keyCode == GLFW.GLFW_KEY_LEFT_ALT || keyCode == GLFW.GLFW_KEY_RIGHT_ALT;
@@ -56,18 +57,18 @@ public enum KeyModifier {
}
@Override
public String getLocalizedComboName(int keyCode)
public String getLocalizedComboName(InputMappings.Input key)
{
String keyName = GLFW.glfwGetKeyName(keyCode, 0);
String keyName = key.func_197936_a();
String localizationFormatKey = Minecraft.IS_RUNNING_ON_MAC ? "forge.controlsgui.control.mac" : "forge.controlsgui.control";
return I18n.format(localizationFormatKey, keyName);
}
},
SHIFT {
@Override
public boolean matches(int keyCode)
public boolean matches(InputMappings.Input key)
{
return keyCode == GLFW.GLFW_KEY_LEFT_SHIFT || keyCode == GLFW.GLFW_KEY_RIGHT_SHIFT;
return key.func_197937_c() == GLFW.GLFW_KEY_LEFT_SHIFT || key.func_197937_c() == GLFW.GLFW_KEY_RIGHT_SHIFT;
}
@Override
@@ -83,17 +84,16 @@ public enum KeyModifier {
}
@Override
public String getLocalizedComboName(int keyCode)
public String getLocalizedComboName(InputMappings.Input key)
{
String keyName = GLFW.glfwGetKeyName(keyCode, 0);
return I18n.format("forge.controlsgui.shift", keyName);
return I18n.format("forge.controlsgui.shift", key.func_197936_a());
}
},
ALT {
@Override
public boolean matches(int keyCode)
public boolean matches(InputMappings.Input key)
{
return keyCode == GLFW.GLFW_KEY_LEFT_ALT || keyCode == GLFW.GLFW_KEY_RIGHT_ALT;
return key.func_197937_c() == GLFW.GLFW_KEY_LEFT_ALT || key.func_197937_c() == GLFW.GLFW_KEY_RIGHT_ALT;
}
@Override
@@ -109,15 +109,14 @@ public enum KeyModifier {
}
@Override
public String getLocalizedComboName(int keyCode)
public String getLocalizedComboName(InputMappings.Input keyCode)
{
String keyName = GLFW.glfwGetKeyName(keyCode, 0);
return I18n.format("forge.controlsgui.alt", keyName);
return I18n.format("forge.controlsgui.alt", keyCode.func_197936_a());
}
},
NONE {
@Override
public boolean matches(int keyCode)
public boolean matches(InputMappings.Input key)
{
return false;
}
@@ -145,9 +144,9 @@ public enum KeyModifier {
}
@Override
public String getLocalizedComboName(int keyCode)
public String getLocalizedComboName(InputMappings.Input key)
{
return GLFW.glfwGetKeyName(keyCode, 0);
return key.func_197936_a();
}
};
@@ -165,11 +164,11 @@ public enum KeyModifier {
return NONE;
}
public static boolean isKeyCodeModifier(int keyCode)
public static boolean isKeyCodeModifier(InputMappings.Input key)
{
for (KeyModifier keyModifier : MODIFIER_VALUES)
{
if (keyModifier.matches(keyCode))
if (keyModifier.matches(key))
{
return true;
}
@@ -189,7 +188,7 @@ public enum KeyModifier {
}
}
public abstract boolean matches(int keyCode);
public abstract boolean matches(InputMappings.Input key);
/**
* @deprecated use {@link #isActive(IKeyConflictContext)}
@@ -199,5 +198,5 @@ public enum KeyModifier {
public abstract boolean isActive(@Nullable IKeyConflictContext conflictContext);
public abstract String getLocalizedComboName(int keyCode);
public abstract String getLocalizedComboName(InputMappings.Input key);
}
@@ -296,7 +296,7 @@ public class DimensionManager
dimensions.get(id).ticksWaited = 0;
}
WorldServer ret = worlds.get(id);
if (ret != null && forceLoad)
if (ret == null && forceLoad)
{
initDimension(id);
ret = worlds.get(id);
@@ -295,20 +295,6 @@ public class ForgeHooks
return ret;
}
static
{
seedList.add(new SeedEntry(new ItemStack(Items.WHEAT_SEEDS), 10)
{
@Override
@Nonnull
public ItemStack getStack(Random rand, int fortune)
{
return new ItemStack(Items.WHEAT_SEEDS, 1 + rand.nextInt(fortune * 2 + 1));
}
});
initTools();
}
/**
* Called when a player uses 'pick block', calls new Entity and Block hooks.
*/
@@ -108,7 +108,7 @@ public class CraftingHelper
public static final IConditionSerializer CONDITION_FALSE = condition("false", json -> () -> false);
public static final IIngredientSerializer<IngredientNBT> INGREDIENT_NBT = register(new ResourceLocation("forge", "nbt"), new IngredientNBT.Serializer());
public static final IIngredientSerializer<CompoundIngredient> INGREDIENT_COMPOUND = register(new ResourceLocation("forge", "nbt"), new CompoundIngredient.Serializer());
public static final IIngredientSerializer<CompoundIngredient> INGREDIENT_COMPOUND = register(new ResourceLocation("forge", "compound"), new CompoundIngredient.Serializer());
public static final IIngredientSerializer<Ingredient> INGREDIENT_VANILLA = register(new ResourceLocation("minecraft", "item"), new IIngredientSerializer<Ingredient>() {
public Ingredient parse(PacketBuffer buffer) {
return Ingredient.func_209357_a(Stream.generate(() -> new Ingredient.SingleItemList(buffer.readItemStack())).limit(buffer.readVarInt()));
@@ -30,7 +30,10 @@ import net.minecraftforge.client.IRenderHandler;
public interface IForgeDimension
{
default Dimension getDimension() { return (Dimension) this; }
default Dimension getDimension()
{
return (Dimension) this;
}
/**
* Called from {@link World#initCapabilities()}, to gather capabilities for this
@@ -50,19 +53,21 @@ public interface IForgeDimension
}
/**
* The dimension's movement factor.
* Whenever a player or entity changes dimension from world A to world B, their coordinates are multiplied by
* The dimension's movement factor. Whenever a player or entity changes
* dimension from world A to world B, their coordinates are multiplied by
* worldA.provider.getMovementFactor() / worldB.provider.getMovementFactor()
* Example: Overworld factor is 1, nether factor is 8. Traveling from overworld to nether multiplies coordinates by 1/8.
* Example: Overworld factor is 1, nether factor is 8. Traveling from overworld
* to nether multiplies coordinates by 1/8.
*
* @return The movement factor
*/
default double getMovementFactor()
{
if (getDimension() instanceof NetherDimension)
{
return 8.0;
}
return 1.0;
if (getDimension() instanceof NetherDimension)
{
return 8.0;
}
return 1.0;
}
/**
@@ -96,4 +101,16 @@ public interface IForgeDimension
@OnlyIn(Dist.CLIENT)
void setWeatherRenderer(IRenderHandler renderer);
void resetRainAndThunder();
default boolean canDoLightning(net.minecraft.world.chunk.Chunk chunk)
{
return true;
}
default boolean canDoRainSnowIce(net.minecraft.world.chunk.Chunk chunk)
{
return true;
}
}
@@ -47,7 +47,6 @@ public interface IForgeFluidState
* @param material to test for.
* @param testingHead when true, its testing the entities head for vision, breathing ect... otherwise its testing the body, for swimming and movement adjustment.
*/
@Nullable
default boolean isEntityInside(IWorldReader world, BlockPos pos, Entity entity, double yToTest, Tag<Fluid> tag, boolean testingHead)
{
return getFluidState().func_206886_c().isEntityInside(getFluidState(), world, pos, entity, yToTest, tag, testingHead);