下面列出了怎么用net.minecraft.util.DyeColor的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Re-colors this block in the world.
*
* @param state The current state
* @param world The world
* @param pos Block position
* @param facing ??? (this method has no usages)
* @param color Color to recolor to.
* @return if the block was affected
*/
@SuppressWarnings("unchecked")
default boolean recolorBlock(BlockState state, IWorld world, BlockPos pos, Direction facing, DyeColor color) {
for (Property<?> prop : state.getProperties()) {
if (prop.getName().equals("color") && prop.getType() == DyeColor.class) {
DyeColor current = (DyeColor) state.get(prop);
if (current != color && prop.getValues().contains(color)) {
world.setBlockState(pos, state.with(((Property<DyeColor>) prop), color), 3);
return true;
}
}
}
return false;
}
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = CommandManager.literal("counter").executes((context)
-> listAllCounters(context.getSource(), false)).requires((player) ->
CarpetSettings.hopperCounters);
literalargumentbuilder.
then((CommandManager.literal("reset").executes( (p_198489_1_)->
resetCounter(p_198489_1_.getSource(), null))));
for (DyeColor enumDyeColor: DyeColor.values())
{
String color = enumDyeColor.toString();
literalargumentbuilder.
then((CommandManager.literal(color).executes( (p_198489_1_)-> displayCounter(p_198489_1_.getSource(), color, false))));
literalargumentbuilder.then(CommandManager.literal(color).
then(CommandManager.literal("reset").executes((context) ->
resetCounter(context.getSource(), color))));
literalargumentbuilder.then(CommandManager.literal(color).
then(CommandManager.literal("realtime").executes((context) ->
displayCounter(context.getSource(), color, true))));
}
dispatcher.register(literalargumentbuilder);
}
public static void registerLoggers()
{
registerLogger("tnt", Logger.stardardLogger( "tnt", "brief", new String[]{"brief", "full"}));
registerLogger("projectiles", Logger.stardardLogger("projectiles", "brief", new String[]{"brief", "full"}));
registerLogger("fallingBlocks",Logger.stardardLogger("fallingBlocks", "brief", new String[]{"brief", "full"}));
//registerLogger("kills", new Logger("kills", null, null));
//registerLogger("damage", new Logger("damage", "all", new String[]{"all","players","me"}));
//registerLogger("weather", new Logger("weather", null, null));
registerLogger( "pathfinding", Logger.stardardLogger("pathfinding", "20", new String[]{"2", "5", "10"}));
registerLogger("tps", HUDLogger.stardardHUDLogger("tps", null, null));
registerLogger("packets", HUDLogger.stardardHUDLogger("packets", null, null));
registerLogger("counter",HUDLogger.stardardHUDLogger("counter","white", Arrays.stream(DyeColor.values()).map(Object::toString).toArray(String[]::new)));
registerLogger("mobcaps", HUDLogger.stardardHUDLogger("mobcaps", "dynamic",new String[]{"dynamic", "overworld", "nether","end"}));
registerLogger("explosions", HUDLogger.stardardLogger("explosions", "brief",new String[]{"brief", "full"}));
}
@Inject(method = "insert", at = @At("HEAD"), cancellable = true)
private void onInsert(CallbackInfoReturnable<Boolean> cir)
{
if (CarpetSettings.hopperCounters) {
DyeColor wool_color = WoolTool.getWoolColorAtPosition(
getWorld(),
new BlockPos(getHopperX(), getHopperY(), getHopperZ()).offset(this.getCachedState().get(HopperBlock.FACING)));
if (wool_color != null)
{
for (int i = 0; i < this.getInvSize(); ++i)
{
if (!this.getInvStack(i).isEmpty())
{
ItemStack itemstack = this.getInvStack(i);//.copy();
HopperCounter.COUNTERS.get(wool_color).add(this.getWorld().getServer(), itemstack);
this.setInvStack(i, ItemStack.EMPTY);
}
}
cir.setReturnValue(true);
}
}
}
@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);
}
public static HopperCounter getCounter(String color)
{
try
{
DyeColor colorEnum = DyeColor.valueOf(color.toUpperCase(Locale.ROOT));
return COUNTERS.get(colorEnum);
}
catch (IllegalArgumentException e)
{
return null;
}
}
public static DyeColor getWoolColorAtPosition(World worldIn, BlockPos pos)
{
BlockState state = worldIn.getBlockState(pos);
if (state.getMaterial() != Material.WOOL || !state.isSimpleFullBlock(worldIn, pos))
return null;
return Material2Dye.get(state.getTopMaterialColor(worldIn, pos));
}
public static List<BaseText> show_mobcaps(BlockPos pos, World worldIn)
{
DyeColor under = WoolTool.getWoolColorAtPosition(worldIn, pos.down());
if (under == null)
{
if (track_spawns > 0L)
{
return tracking_report(worldIn);
}
else
{
return printMobcapsForDimension(worldIn.dimension.getType(), true );
}
}
EntityCategory creature_type = get_type_code_from_wool_code(under);
if (creature_type != null)
{
if (track_spawns > 0L)
{
return recent_spawns(worldIn, creature_type);
}
else
{
return printEntitiesByType(creature_type, worldIn, true);
}
}
if (track_spawns > 0L)
{
return tracking_report(worldIn);
}
else
{
return printMobcapsForDimension(worldIn.dimension.getType(), true );
}
}
public static EntityCategory get_type_code_from_wool_code(DyeColor color)
{
switch (color)
{
case RED:
return EntityCategory.MONSTER;
case GREEN:
return EntityCategory.CREATURE;
case BLUE:
return EntityCategory.WATER_CREATURE;
case BROWN:
return EntityCategory.AMBIENT;
}
return null;
}
public FluidPipeBlock(Settings settings) {
super(settings);
setDefaultState(this.getStateManager().getDefaultState().with(PULL, false).with(COLOR, DyeColor.WHITE).with(ATTACHED_NORTH, false).with(ATTACHED_EAST, false).with(ATTACHED_SOUTH, false).with(ATTACHED_WEST, false).with(ATTACHED_UP, false).with(ATTACHED_DOWN, false));
}
public HallowedCarpetBlock(DyeColor color, Settings settings) {
super(color, settings);
}
@Inject(method = "fromTag", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;fromTag(Lnet/minecraft/block/BlockState;Lnet/minecraft/nbt/CompoundTag;)V", shift = At.Shift.AFTER))
private void readBase(BlockState blockState, CompoundTag tag, CallbackInfo ci) {
if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) {
setBaseColor(DyeColor.byId(15 - tag.getInt("Base")));
}
}
@Shadow
public abstract DyeColor getColor();
private HopperCounter(DyeColor color)
{
this.color = color;
// pubSubProvider = new PubSubInfoProvider<>(QuickCarpet.PUBSUB, "carpet.counter." + color.getName(), 0, this::getTotalItems);
}
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("spawn").
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandSpawn));
literalargumentbuilder.
then(literal("list").
then(argument("pos", BlockPosArgumentType.blockPos()).
executes( (c) -> listSpawns(c.getSource(), BlockPosArgumentType.getBlockPos(c, "pos"))))).
then(literal("tracking").
executes( (c) -> printTrackingReport(c.getSource())).
then(literal("start").
executes( (c) -> startTracking(c.getSource(), null, null)).
then(argument("from", BlockPosArgumentType.blockPos()).
then(argument("to", BlockPosArgumentType.blockPos()).
executes( (c) -> startTracking(
c.getSource(),
BlockPosArgumentType.getBlockPos(c, "from"),
BlockPosArgumentType.getBlockPos(c, "to")))))).
then(literal("stop").
executes( (c) -> stopTracking(c.getSource()))).
then(argument("type", word()).
suggests( (c, b) -> suggestMatching(Arrays.stream(EntityCategory.values()).map(EntityCategory::getName),b)).
executes( (c) -> recentSpawnsForType(c.getSource(), getString(c, "type"))))).
then(literal("test").
executes( (c)-> runTest(c.getSource(), 72000, null)).
then(argument("ticks", integer(10,720000)).
executes( (c)-> runTest(
c.getSource(),
getInteger(c, "ticks"),
null)).
then(argument("counter", word()).
suggests( (c, b) -> suggestMatching(Arrays.stream(DyeColor.values()).map(DyeColor::toString),b)).
executes((c)-> runTest(
c.getSource(),
getInteger(c, "ticks"),
getString(c, "counter")))))).
then(literal("mocking").
then(argument("to do or not to do?", BoolArgumentType.bool()).
executes( (c) -> toggleMocking(c.getSource(), BoolArgumentType.getBool(c, "to do or not to do?"))))).
then(literal("rates").
executes( (c) -> generalMobcaps(c.getSource())).
then(literal("reset").
executes( (c) -> resetSpawnRates(c.getSource()))).
then(argument("type", word()).
suggests( (c, b) -> suggestMatching(Arrays.stream(EntityCategory.values()).map(EntityCategory::getName),b)).
then(argument("rounds", integer(0)).
suggests( (c, b) -> suggestMatching(new String[]{"1"},b)).
executes( (c) -> setSpawnRates(
c.getSource(),
getString(c, "type"),
getInteger(c, "rounds")))))).
then(literal("mobcaps").
executes( (c) -> generalMobcaps(c.getSource())).
then(literal("set").
then(argument("cap (hostile)", integer(1,1400)).
executes( (c) -> setMobcaps(c.getSource(), getInteger(c, "cap (hostile)"))))).
then(argument("dimension", DimensionArgumentType.dimension()).
executes( (c)-> mobcapsForDimension(c.getSource(), DimensionArgumentType.getDimensionArgument(c, "dimension"))))).
then(literal("entities").
executes( (c) -> generalMobcaps(c.getSource()) ).
then(argument("type", string()).
suggests( (c, b)->suggestMatching(Arrays.stream(EntityCategory.values()).map(EntityCategory::getName), b)).
executes( (c) -> listEntitiesOfType(c.getSource(), getString(c, "type"), false)).
then(literal("all").executes( (c) -> listEntitiesOfType(c.getSource(), getString(c, "type"), true)))));
dispatcher.register(literalargumentbuilder);
}
/**
* Re-colors this block in the world.
*
* @param state The current state
* @param world The world
* @param pos Block position
* @param facing ??? (this method has no usages)
* @param color Color to recolor to.
* @return if the block was affected
*/
default boolean recolorBlock(IWorld world, BlockPos pos, Direction facing, DyeColor color) {
return patchwork$getForgeBlock().recolorBlock(getBlockState(), world, pos, facing, color);
}
@Shadow public abstract void setColor(DyeColor color);