org.spongepowered.asm.mixin.Unique Java Examples

The following examples show how to use org.spongepowered.asm.mixin.Unique. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MixinSkullBlockEntity.java    From multiconnect with MIT License 6 votes vote down vote up
@Unique
public void setSkullType(int skullType) {
    BlockState state = getCachedState();
    if (!getType().supports(state.getBlock()))
        return;

    if (skullType < 0 || skullType > 5)
        skullType = 0;

    final Block[] skullBlocks = {Blocks.SKELETON_SKULL, Blocks.WITHER_SKELETON_SKULL, Blocks.ZOMBIE_HEAD, Blocks.PLAYER_HEAD, Blocks.CREEPER_HEAD, Blocks.DRAGON_HEAD};
    final Block[] wallSkullBlocks = {Blocks.SKELETON_WALL_SKULL, Blocks.WITHER_SKELETON_WALL_SKULL, Blocks.ZOMBIE_WALL_HEAD, Blocks.PLAYER_WALL_HEAD, Blocks.CREEPER_WALL_HEAD, Blocks.DRAGON_WALL_HEAD};
    assert world != null;
    if (state.getBlock() instanceof WallSkullBlock) {
        world.setBlockState(pos, wallSkullBlocks[skullType].getDefaultState().with(WallSkullBlock.FACING, state.get(WallSkullBlock.FACING)), 18);
    } else {
        world.setBlockState(pos, skullBlocks[skullType].getDefaultState().with(SkullBlock.ROTATION, state.get(SkullBlock.ROTATION)), 18);
    }
}
 
Example #2
Source File: WorldRendererMixin.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Unique
private float getStarBrightness(float delta) {
    final float var2 = this.world.getSkyAngle(delta);
    float var3 = 1.0F - (MathHelper.cos((float) (var2 * Math.PI * 2.0D) * 2.0F + 0.25F));

    if (var3 < 0.0F) {
        var3 = 0.0F;
    }

    if (var3 > 1.0F) {
        var3 = 1.0F;
    }

    return var3 * var3 * 0.5F + 0.3F;
}
 
Example #3
Source File: MixinInfo.java    From Mixin with MIT License 5 votes vote down vote up
/**
 * Performs pre-flight checks on the mixin
 * 
 * @param type Mixin Type
 * @param targetClasses Mixin's target classes
 */
void validate(SubType type, List<ClassInfo> targetClasses) {
    MixinClassNode classNode = this.getValidationClassNode();
    MixinPreProcessorStandard preProcessor = type.createPreProcessor(classNode).prepare();
    for (ClassInfo target : targetClasses) {
        preProcessor.conform(target);
    }
    
    type.validate(this, targetClasses);

    this.detachedSuper = type.isDetachedSuper();
    this.unique = Annotations.getVisible(classNode, Unique.class) != null;

    // Pre-flight checks
    this.validateInner();
    this.validateClassVersion();
    this.validateRemappables(targetClasses);

    // Read information from the mixin
    this.readImplementations(type);
    this.readInnerClasses();
    
    // Takeoff validation
    this.validateChanges(type, targetClasses);
    
    // Null out the validation classnode
    this.complete();
}
 
Example #4
Source File: MixinClientPlayNetworkHandler.java    From multiconnect with MIT License 5 votes vote down vote up
@Unique
private void applyPendingEntityTrackerValues(int entityId) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_14_4) {
        List<DataTracker.Entry<?>> entries = PendingDataTrackerEntries.getEntries(entityId);
        if (entries != null) {
            PendingDataTrackerEntries.setEntries(entityId, null);
            EntityTrackerUpdateS2CPacket trackerPacket = new EntityTrackerUpdateS2CPacket();
            //noinspection ConstantConditions
            TrackerUpdatePacketAccessor trackerPacketAccessor = (TrackerUpdatePacketAccessor) trackerPacket;
            trackerPacketAccessor.setId(entityId);
            trackerPacketAccessor.setTrackedValues(entries);
            onEntityTrackerUpdate(trackerPacket);
        }
    }
}
 
Example #5
Source File: MixinBannerBlockEntity.java    From multiconnect with MIT License 5 votes vote down vote up
@Unique
private void setBaseColor(DyeColor color) {
    BlockState state = getCachedState();
    if (!getType().supports(state.getBlock()))
        return;

    BlockState newState;
    if (state.getBlock() instanceof WallBannerBlock) {
        newState = WALL_BANNERS_BY_COLOR.get(color).getDefaultState().with(WallBannerBlock.FACING, state.get(WallBannerBlock.FACING));
    } else {
        newState = BannerBlock.getForColor(color).getDefaultState().with(BannerBlock.ROTATION, state.get(BannerBlock.ROTATION));
    }
    assert world != null;
    world.setBlockState(getPos(), newState, 18);
}
 
Example #6
Source File: MixinBlockStateFlattening.java    From multiconnect with MIT License 5 votes vote down vote up
@Unique
private static void handleOldState(String old) {
    Dynamic<?> oldState = BlockStateFlattening.parseState(old);
    Identifier id = new Identifier(oldState.get("Name").asString(""));
    Map<String, String> properties = oldState.get("Properties").asMap(k -> k.asString(""), v -> v.asString(""));
    BlockStateReverseFlattening.OLD_PROPERTIES.computeIfAbsent(id, k -> properties.keySet().stream().sorted().collect(Collectors.toList()));
    properties.forEach((name, value) -> {
        List<String> values = BlockStateReverseFlattening.OLD_PROPERTY_VALUES.computeIfAbsent(Pair.of(id, name), k -> new ArrayList<>());
        if (!values.contains(value))
            values.add(value);
    });
}
 
Example #7
Source File: MixinBedBlockEntity.java    From multiconnect with MIT License 5 votes vote down vote up
@Unique
public void setBedColor(int color) {
    setColor(DyeColor.byId(color));

    BlockState state = getCachedState();
    if (!getType().supports(state.getBlock()))
        return;

    if (color < 0 || color > 15)
        color = 0;

    final Block[] beds = new Block[] {
            Blocks.WHITE_BED,
            Blocks.ORANGE_BED,
            Blocks.MAGENTA_BED,
            Blocks.LIGHT_BLUE_BED,
            Blocks.YELLOW_BED,
            Blocks.LIME_BED,
            Blocks.PINK_BED,
            Blocks.GRAY_BED,
            Blocks.LIGHT_GRAY_BED,
            Blocks.CYAN_BED,
            Blocks.PURPLE_BED,
            Blocks.BLUE_BED,
            Blocks.BROWN_BED,
            Blocks.GREEN_BED,
            Blocks.RED_BED,
            Blocks.BLACK_BED};
    assert world != null;
    world.setBlockState(pos, beds[color].getDefaultState().with(BedBlock.FACING, state.get(BedBlock.FACING)).with(BedBlock.PART, state.get(BedBlock.PART)), 18);
}
 
Example #8
Source File: MixinSkullBlockEntity.java    From multiconnect with MIT License 5 votes vote down vote up
@Unique
public void setRotation(int rot) {
    BlockState state = getCachedState();
    if (!getType().supports(state.getBlock()) || !(state.getBlock() instanceof SkullBlock))
        return;

    assert world != null;
    world.setBlockState(pos, state.with(SkullBlock.ROTATION, rot & 15));
}
 
Example #9
Source File: ClassInfo.java    From Mixin with MIT License 5 votes vote down vote up
public Field(FieldNode field, boolean injected) {
    super(Type.FIELD, field.name, field.desc, field.access, injected);
    
    this.setUnique(Annotations.getVisible(field, Unique.class) != null);
    
    if (Annotations.getVisible(field, Shadow.class) != null) {
        boolean decoratedFinal = Annotations.getVisible(field, Final.class) != null;
        boolean decoratedMutable = Annotations.getVisible(field, Mutable.class) != null;
        this.setDecoratedFinal(decoratedFinal, decoratedMutable);
    }
}
 
Example #10
Source File: MixinClientPlayNetworkHandler.java    From multiconnect with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Unique
private static <T> TagRegistry<T> setExtraTags(TagContainer<T> container, Consumer<TagRegistry<T>> tagsAdder) {
    TagContainerAccessor<T> accessor = (TagContainerAccessor<T>) container;
    TagRegistry<T> tags = new TagRegistry<>();
    container.getEntries().forEach((id, tag) -> tags.put(id, new HashSet<>(tag.values())));
    tagsAdder.accept(tags);
    BiMap<Identifier, Tag<T>> tagBiMap = HashBiMap.create(tags.size());
    tags.forEach((id, set) -> tagBiMap.put(id, Tag.of(set)));
    accessor.multiconnect_setEntries(tagBiMap);
    return tags;
}
 
Example #11
Source File: MixinClientPlayNetworkHandler.java    From multiconnect with MIT License 5 votes vote down vote up
@Unique
private static void checkRequiredTags(RegistryTagManager tagManager) {
    Multimap<String, Identifier> missingTags = HashMultimap.create();
    missingTags.putAll("blocks", BlockTags.method_29214(tagManager.blocks()));
    missingTags.putAll("items", ItemTags.method_29217(tagManager.items()));
    missingTags.putAll("fluids", FluidTags.method_29216(tagManager.fluids()));
    missingTags.putAll("entity_types", EntityTypeTags.method_29215(tagManager.entityTypes()));
    if (!missingTags.isEmpty()) {
        LogManager.getLogger("multiconnect").error("Missing required tags: " + missingTags.entries().stream()
                .map(entry -> entry.getKey() + ":" + entry.getValue())
                .sorted()
                .collect(Collectors.joining(",")));
    }
}
 
Example #12
Source File: ClassInfo.java    From Mixin with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public Method(MethodNode method, boolean injected) {
    super(Type.METHOD, method.name, method.desc, method.access, injected);
    this.frames = this.gatherFrames(method);
    this.setUnique(Annotations.getVisible(method, Unique.class) != null);
    this.isAccessor = Annotations.getSingleVisible(method, Accessor.class, Invoker.class) != null;
    boolean decoratedFinal = Annotations.getVisible(method, Final.class) != null;
    boolean decoratedMutable = Annotations.getVisible(method, Mutable.class) != null;
    this.setDecoratedFinal(decoratedFinal, decoratedMutable);
}
 
Example #13
Source File: MixinMultiplayerScreen.java    From ViaFabric with MIT License 5 votes vote down vote up
@Unique
private int getTextColor() {
    if (!validProtocol) {
        return 0xff0000; // Red
    } else if (!supportedProtocol) {
        return 0xFFA500; // Orange
    }
    return 0xE0E0E0; // Default
}
 
Example #14
Source File: InterfaceInfo.java    From Mixin with MIT License 5 votes vote down vote up
/**
 * Decorate the target method with {@link Unique} if the interface is marked
 * as unique
 * 
 * @param method method to decorate
 */
private void decorateUniqueMethod(MethodNode method) {
    if (!this.unique) {
        return;
    }
    
    if (Annotations.getVisible(method, Unique.class) == null) {
        Annotations.setVisible(method, Unique.class);
        this.mixin.getClassInfo().findMethod(method).setUnique(true);
    }
}
 
Example #15
Source File: MixinPreProcessorStandard.java    From Mixin with MIT License 4 votes vote down vote up
protected boolean attachUniqueMethod(MixinTargetContext context, MixinMethodNode mixinMethod) {
    Method method = this.mixin.getClassInfo().findMethod(mixinMethod, ClassInfo.INCLUDE_ALL);
    if (method == null || ((!method.isUnique() && !this.mixin.isUnique()) && !method.isSynthetic())) {
        return false;
    }
    
    boolean synthetic = method.isSynthetic();
    if (synthetic) {
        context.transformDescriptor(mixinMethod);
        method.remapTo(mixinMethod.desc);
    }

    MethodNode target = context.findMethod(mixinMethod, null);
    if (target == null && !synthetic) {
        return false;
    }
    
    String type = synthetic ? "synthetic" : "@Unique";
    
    if (Bytecode.getVisibility(mixinMethod).ordinal() < Visibility.PUBLIC.ordinal()) {
        if (method.isConformed()) {
            mixinMethod.name = method.getName();
        } else {
            String uniqueName = context.getUniqueName(mixinMethod, false);
            MixinPreProcessorStandard.logger.log(this.mixin.getLoggingLevel(), "Renaming {} method {}{} to {} in {}",
                    type, mixinMethod.name, mixinMethod.desc, uniqueName, this.mixin);
            mixinMethod.name = method.conform(uniqueName);
        }
        return false;
    }

    if (target == null) {
        return false;
    }
    
    if (this.strictUnique) {
        throw new InvalidMixinException(this.mixin, String.format("Method conflict, %s method %s in %s cannot overwrite %s%s in %s",
                type, mixinMethod.name, this.mixin, target.name, target.desc, context.getTarget()));
    }
    
    AnnotationNode unique = Annotations.getVisible(mixinMethod, Unique.class);
    if (unique == null || !Annotations.<Boolean>getValue(unique, "silent", Boolean.FALSE).booleanValue()) {
        if (Bytecode.hasFlag(mixinMethod, Opcodes.ACC_BRIDGE)) {
            try {
                // will throw exception if bridge methods are incompatible
                Bytecode.compareBridgeMethods(target, mixinMethod);
                MixinPreProcessorStandard.logger.debug("Discarding sythetic bridge method {} in {} because existing method in {} is compatible",
                        type, mixinMethod.name, this.mixin, context.getTarget());
                return true;
            } catch (SyntheticBridgeException ex) {
                if (this.verboseLogging || this.env.getOption(Option.DEBUG_VERIFY)) {
                    // Show analysis if debug options are active, implying we're in a dev environment
                    ex.printAnalysis(context, target, mixinMethod);
                }
                throw new InvalidMixinException(this.mixin, ex.getMessage());
            }
        }
        
        MixinPreProcessorStandard.logger.warn("Discarding {} public method {} in {} because it already exists in {}", type, mixinMethod.name,
                this.mixin, context.getTarget());
        return true;
    }

    context.addMixinMethod(mixinMethod);
    return true;
}
 
Example #16
Source File: MixinMultiplayerScreen.java    From ViaFabric with MIT License 4 votes vote down vote up
@Unique
private boolean isSupported(int protocol) {
    return ProtocolRegistry.getProtocolPath(ProtocolRegistry.SERVER_PROTOCOL, protocol) != null
            || ProtocolRegistry.SERVER_PROTOCOL == protocol;
}
 
Example #17
Source File: MixinDisconnectedScreen.java    From multiconnect with MIT License 4 votes vote down vote up
@Unique
private ConnectionMode getForcedVersion() {
    int protocolVersion = ServersExt.getInstance().getForcedProtocol(server.address);
    return ConnectionMode.byValue(protocolVersion);
}
 
Example #18
Source File: MixinPacketHandler.java    From multiconnect with MIT License 4 votes vote down vote up
@Unique
@SuppressWarnings("unchecked")
private static <T extends PacketListener, P extends Packet<T>> PacketInfo<P> createPacketInfo(Class<?> packetClass, Supplier<?> factory) {
    return PacketInfo.of((Class<P>) packetClass, (Supplier<P>) factory);
}
 
Example #19
Source File: MixinRecipeBookWidget.java    From multiconnect with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Unique
private static <C extends Inventory> void handleRecipeClicked(RecipeBook_1_12<C> recipeBook112, Recipe<?> recipe, RecipeResultCollection results) {
    recipeBook112.handleRecipeClicked((Recipe<C>) recipe, results);
}
 
Example #20
Source File: WorldRendererMixin.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Unique
private void generateStarBufferMoon() {
    Random random = new Random(1671120782L);

    BufferBuilder buffer = Tessellator.getInstance().getBuffer();
    buffer.begin(7, VertexFormats.POSITION);
    for (int i = 0; i < 12000; ++i) {
        double j = random.nextFloat() * 2.0F - 1.0F;
        double k = random.nextFloat() * 2.0F - 1.0F;
        double l = random.nextFloat() * 2.0F - 1.0F;
        double m = 0.15F + random.nextFloat() * 0.1F;
        double n = j * j + k * k + l * l;

        if (n < 1.0D && n > 0.01D) {
            n = 1.0D / Math.sqrt(n);
            j *= n;
            k *= n;
            l *= n;
            double o = j * 100.0D;
            double p = k * 100.0D;
            double q = l * 100.0D;
            double r = Math.atan2(j, l);
            double s = Math.sin(r);
            double t = Math.cos(r);
            double u = Math.atan2(Math.sqrt(j * j + l * l), k);
            double v = Math.sin(u);
            double w = Math.cos(u);
            double x = random.nextDouble() * Math.PI * 2.0D;
            double y = Math.sin(x);
            double z = Math.cos(x);

            for (int a = 0; a < 4; ++a) {
                double b = 0.0D;
                double c = ((a & 2) - 1) * m;
                double d = ((a + 1 & 2) - 1) * m;
                double e = c * z - d * y;
                double f = d * z + c * y;
                double g = e * v + b * w;
                double h = b * v - e * w;
                double aa = h * s - f * t;
                double ab = f * s + h * t;
                buffer.vertex((o + aa) * (i > 6000 ? -1 : 1), (p + g) * (i > 6000 ? -1 : 1), (q + ab) * (i > 6000 ? -1 : 1)).next();
            }
        }
    }
    buffer.end();
    starBufferMoon.upload(buffer);
}