下面列出了net.minecraft.util.EntitySelectors#net.minecraftforge.fml.relauncher.Side 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void useNetworkData(EntityPlayer player, Side side, byte id,
NBTTagCompound nbt) {
if(side.isClient()) {
if(id == 3) {
EnumFacing dir = RotatableBlock.getFront(world.getBlockState(pos));
LibVulpes.proxy.playSound(world, pos, AudioRegistry.railgunFire, SoundCategory.BLOCKS, Minecraft.getMinecraft().gameSettings.getSoundLevel(SoundCategory.BLOCKS), 0.975f + world.rand.nextFloat()*0.05f);
recoil = world.getTotalWorldTime();
}
}
else if(id == 4) {
minStackTransferSize = nbt.getInteger("minTransferSize");
}
else if(id == 5) {
state = RedstoneState.values()[nbt.getByte("state")];
}
else
super.useNetworkData(player, side, id, nbt);
}
/**
* Tries to move an item stack form the correct tile entity to the player's inventory
*/
public void moveStackFromTileEntityToPlayer(int slotId, ItemStack stack) {
ISeedStorageControllable controllable = this.getControllable(stack).orElse(null);
if (controllable == null) {
return;
}
ItemStack stackToMove = controllable.getStackForSlotId(slotId);
if (stack.isEmpty()) {
return;
}
if (stackToMove.isEmpty()) {
return;
}
stackToMove.setCount(stack.getCount() > stackToMove.getCount() ? stackToMove.getCount() : stack.getCount());
stackToMove.setTagCompound(controllable.getStackForSlotId(slotId).getTagCompound());
if (this.mergeItemStack(stackToMove, 0, PLAYER_INVENTORY_SIZE, false)) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
//this method is only called form the gui client side, so we need to manually tell the server to execute it there
new MessageContainerSeedStorage(stack, slotId).sendToServer();
} else {
//on the server decrease the size of the stack, where it is synced to the client
controllable.decreaseStackSizeInSlot(slotId, stack.getCount() - stackToMove.getCount());
}
}
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public static void onScroll(MouseEvent event) {
EntityPlayer player = Minecraft.getMinecraft().player;
if (player == null) return;
if (Keyboard.isCreated() && event.getDwheel() != 0) {
for (EnumHand hand : EnumHand.values()) {
ItemStack stack = player.getHeldItem(hand);
if (stack.getItem() != ModItems.FAIRY_BELL)
continue;
IMiscCapability cap = MiscCapabilityProvider.getCap(Minecraft.getMinecraft().player);
if (cap == null) continue;
cap.setSelectedFairy(null);
PacketHandler.NETWORK.sendToServer(new PacketUpdateMiscCapToServer(cap.serializeNBT()));
}
}
}
@SideOnly(Side.CLIENT)
public static void initModels()
{
dust.initModel();
netherrackCrushed.initModel();
endstoneCrushed.initModel();
barrelWood.initModel();
barrelStone.initModel();
sieve.initModel();
crucible.initModel();
infestedLeaves.initModel();
fluidWitchwater.initModel();
}
@SideOnly(Side.CLIENT)
private static void initClient() {
registerClientExecutor(PacketUIOpen.class, (packet, handler) -> {
UIFactory<?> uiFactory = UIFactory.FACTORY_REGISTRY.getObjectById(packet.uiFactoryId);
if (uiFactory == null) {
GTLog.logger.warn("Couldn't find UI Factory with id '{}'", packet.uiFactoryId);
} else {
uiFactory.initClientUI(packet.serializedHolder, packet.windowId, packet.initialWidgetUpdates);
}
});
registerClientExecutor(PacketUIWidgetUpdate.class, (packet, handler) -> {
GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
if(currentScreen instanceof ModularUIGui) {
((ModularUIGui) currentScreen).handleWidgetUpdate(packet);
}
});
registerClientExecutor(PacketBlockParticle.class, (packet, handler) -> {
World world = Minecraft.getMinecraft().world;
IBlockState blockState = world.getBlockState(packet.blockPos);
ParticleManager particleManager = Minecraft.getMinecraft().effectRenderer;
((ICustomParticleBlock) blockState.getBlock()).handleCustomParticle(world, packet.blockPos, particleManager, packet.entityPos, packet.particlesAmount);
});
}
@Override
public void useNetworkData(EntityPlayer player, Side side, byte id,
NBTTagCompound nbt) {
if(id == PACKET_REDSTONE_ID)
state = RedstoneState.values()[nbt.getByte("state")];
else if(id == PACKET_TRACE_ID) {
allowTrace = nbt.getBoolean("trace");
if(!allowTrace)
radius = -1;
}
}
@Override
public void readFromStreamStream(Side side, EntityPlayer player, PacketBuffer input) throws IOException {
syncProvider.readFromStreamStream(side, player, input);
SyncMap map = getSyncMap();
objectId = input.readVarInt();
object = map.getObjectById(objectId);
}
@Override
@SideOnly(Side.CLIENT)
public void renderSpell(World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
Vec3d position = spell.getTarget(world);
if (position == null) return;
ParticleBuilder glitter = new ParticleBuilder(1);
glitter.setAlphaFunction(new InterpFloatInOut(0.0f, 0.1f));
glitter.setColorFunction(new InterpColorHSV(instance.getPrimaryColor(), instance.getSecondaryColor()));
glitter.enableMotionCalculation();
glitter.setScaleFunction(new InterpScale(1, 0));
glitter.setAcceleration(new Vec3d(0, -0.05, 0));
glitter.setCollision(true);
glitter.setCanBounce(true);
ParticleSpawner.spawn(glitter, world, new StaticInterp<>(position), RandUtil.nextInt(20, 30), 0, (aFloat, particleBuilder) -> {
if (RandUtil.nextInt(5) == 0) {
glitter.setRenderNormalLayer(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED));
} else {
glitter.setRender(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED));
}
glitter.setScale(RandUtil.nextFloat());
glitter.setLifetime(RandUtil.nextInt(50, 100));
glitter.addMotion(new Vec3d(RandUtil.nextDouble(-0.05, 0.05), RandUtil.nextDouble(0.01, 0.05), RandUtil.nextDouble(-0.05, 0.05)));
});
}
@SideOnly(Side.CLIENT)
@Override
public void renderPilotText(FontRenderer renderer, ScaledResolution gameResolution) {
// White text.
int color = 0xFFFFFF;
// Extra spaces so the that the text is closer to the middle when rendered.
String message = "Wheel Rotation: ";
int i = gameResolution.getScaledWidth();
int height = gameResolution.getScaledHeight() - 35;
float middle = (float) (i / 2 - renderer.getStringWidth(message) / 2);
message = "Wheel Rotation: " + Math.round(wheelRotation);
renderer.drawStringWithShadow(message, middle, height, color);
}
@Override
@SideOnly(Side.CLIENT)
public void handle(@NotNull MessageContext ctx) {
if (pos == null) return;
World world = Minecraft.getMinecraft().world;
BounceManager.INSTANCE.forBlock(world, pos, time);
BounceBlockRenderer.addBounce(world, pos, time);
}
@Override
public void handle(@Nonnull MessageContext ctx) {
ClientRunnable.run(new ClientRunnable() {
@Override
@SideOnly(Side.CLIENT)
public void runIfClient() {
NemezTracker tracker = NemezEventHandler.getCurrent();
tracker.absorb(nemez.getTagList("root", Constants.NBT.TAG_COMPOUND));
}
});
}
@SideOnly(Side.CLIENT)
@Nonnull
public TextureAtlasSprite getIcon() {
if (texture == null) {
try {
IBlockState state = block.getStateFromMeta(meta);
texture = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getTexture(state);
} catch (Exception e) {
AgriCore.getLogger("agricraft").debug("Unable to load texture for custom wood block {0}!", block.getLocalizedName());
AgriCore.getLogger("agricraft").trace(e);
texture = Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
}
}
return texture;
}
public ItemTofuForceCore() {
super();
this.setMaxStackSize(1);
this.setMaxDamage(360);
this.setUnlocalizedName(TofuMain.MODID + "." + "tofuforce_core");
this.addPropertyOverride(new ResourceLocation("broken"), new IItemPropertyGetter() {
@SideOnly(Side.CLIENT)
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) {
return isUsable(stack) ? 0.0F : 1.0F;
}
});
}
@Override
public IMessage onMessage(final MessageGuiAction message, MessageContext ctx)
{
if (ctx.side != Side.SERVER)
{
EnderUtilities.logger.error("Wrong side in MessageGuiAction: " + ctx.side);
return null;
}
final EntityPlayerMP sendingPlayer = ctx.getServerHandler().player;
if (sendingPlayer == null)
{
EnderUtilities.logger.error("Sending player was null in MessageGuiAction");
return null;
}
final WorldServer playerWorldServer = sendingPlayer.getServerWorld();
if (playerWorldServer == null)
{
EnderUtilities.logger.error("World was null in MessageGuiAction");
return null;
}
playerWorldServer.addScheduledTask(new Runnable()
{
public void run()
{
processMessage(message, sendingPlayer);
}
});
return null;
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
{
for (BlockAlienPlank.EnumType BlockAlienPlank$enumtype : BlockAlienPlank.EnumType.values())
{
list.add(new ItemStack(itemIn, 1, BlockAlienPlank$enumtype.getMetadata()));
}
}
@Override
@SideOnly(Side.CLIENT)
public void drawInBackground(int mouseX, int mouseY, IRenderContext context) {
if (!this.isVisible || area == null) return;
Position position = getPosition();
Size size = getSize();
area.draw(position.x, position.y, size.width, size.height);
}
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
if (event.getSide() == Side.CLIENT) {
// ---- initialize mods ----//
getModManager().loadAll();
}
}
@Override
@SideOnly(Side.CLIENT)
public Gui getGui(EntityPlayer player, short id) {
switch (id) {
case 1:
return new GuiUpgrades(new ContainerUpgrades(this, player));
default:
return new GuiBarrel(new ContainerBarrel(this, player));
}
}
@Override
@SideOnly(Side.CLIENT)
protected int getColorForItemStack(ItemStack stack, int tintIndex) {
if (tintIndex == 0 && stack.getMetadata() < metaItemOffset) {
Material material = Material.MATERIAL_REGISTRY.getObjectById(stack.getMetadata() % 1000);
if (material == null) return 0xFFFFFF;
return material.materialRGB;
}
return super.getColorForItemStack(stack, tintIndex);
}
@Override
public void useNetworkData(EntityPlayer player, Side side, byte id,
NBTTagCompound nbt) {
if(id == PACKET_WRITE_DST_INFO && world.isRemote) {
if(nbt.hasKey("dimid")) {
dstTilePos = new DimensionBlockPosition(nbt.getInteger("dimid"), new HashedBlockPosition(nbt.getInteger("x"), nbt.getInteger("y"), nbt.getInteger("z")));
}
else dstTilePos = null;
}
else if(id == PACKET_WRITE_SRC_INFO && world.isRemote) {
if(nbt.hasKey("dimid")) {
srcTilePos = new DimensionBlockPosition(nbt.getInteger("dimid"), new HashedBlockPosition(nbt.getInteger("x"), nbt.getInteger("y"), nbt.getInteger("z")));
}
else srcTilePos = null;
}
else if(id == PACKET_RECIEVE_NBT) {
PacketHandler.sendToPlayersTrackingEntity(new PacketEntity(this, PACKET_WRITE_DST_INFO), this);
}
else if(id == PACKET_LAUNCH_EVENT && world.isRemote) {
List<EntityPlayer> list = world.getEntitiesWithinAABB(EntityPlayer.class, getEntityBoundingBox());
for(Entity ent : list) {
if(this.getRidingEntity() == null)
ent.startRiding(this);
}
MinecraftForge.EVENT_BUS.post(new RocketEvent.RocketLaunchEvent(this));
}
else if(id == PACKET_DEORBIT && world.isRemote) {
MinecraftForge.EVENT_BUS.post(new RocketEvent.RocketDeOrbitingEvent(this));
}
}
/**
* Renders this meta tile entity
* Note that you shouldn't refer to world-related information in this method, because it
* will be called on ItemStacks too
*
* @param renderState render state (either chunk batched or item)
* @param pipeline default set of pipeline transformations
*/
@SideOnly(Side.CLIENT)
public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation, IVertexOperation[] pipeline) {
TextureAtlasSprite atlasSprite = TextureUtils.getMissingSprite();
IVertexOperation[] renderPipeline = ArrayUtils.add(pipeline, new ColourMultiplier(GTUtility.convertRGBtoOpaqueRGBA_CL(getPaintingColorForRendering())));
for (EnumFacing face : EnumFacing.VALUES) {
Textures.renderFace(renderState, translation, renderPipeline, face, Cuboid6.full, atlasSprite);
}
}
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World world,
BlockPos pos, Random rand) {
super.randomDisplayTick(stateIn, world, pos, rand);
if(world.getTotalWorldTime() % 100 == 0 && world.getBiome(pos) == AdvancedRocketryBiomes.stormLandsBiome) {
FxSystemElectricArc.spawnArc(world, pos.getX() + 0.5f, pos.getY() + 0.5f, pos.getZ() + 0.5f, .3, 7);
world.playSound(Minecraft.getMinecraft().player, pos, AudioRegistry.electricShockSmall, SoundCategory.BLOCKS, .7f, 0.975f + world.rand.nextFloat()*0.05f);
}
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> subItems) {
if (isInCreativeTab(tab)) {
for (Entry<Integer, IMetaItem> entry : metaitems.entrySet())
entry.getValue().addToCreativeList(this, entry.getKey(), subItems);
}
}
@Override
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState,
IBlockAccess world, BlockPos pos, EnumFacing side) {
EnumFacing dir = side;//side.getOpposite();
IBlockState blockState2 = world.getBlockState(pos.offset(dir));
return blockState.equals(blockState2) ? false : super.shouldSideBeRendered(blockState, world, pos, side);
}
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void addHudElements(CyberwareHudEvent event)
{
if (event.isHudjackAvailable())
{
event.addElement(pd);
event.addElement(mpd);
event.addElement(nd);
}
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer playerIn,
List<String> tooltip, boolean advanced) {
if (!this.getUnlocalizedName().equals("container_wand")) {
return;
}
tooltip.add(EnumChatFormatting.DARK_RED
+ "Right click on a container's \"Name:\" sign to remove the container.");
}
@SideOnly(Side.CLIENT)
public static void render() {
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCampfire.class, new RenderTileEntityCampfire());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityStoneMortar.class, new RenderTileEntityStoneMortar());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCampfirePot.class, new RenderTileEntityCampfirePot());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMapleCauldron.class, new RenderTileEntityMapleCauldron());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityShoji.class, new ShojiRender());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityOben.class, new RenderTileEntityOben());
getItem(BlockLoader.STONEMORTAR).setTileEntityItemStackRenderer(new TileEntityRenderHelper());
}
/*******************************************************************************
* 2. Rendering
*******************************************************************************/
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand)
{
TileFirepit te = (TileFirepit)world.getTileEntity(pos);
if(te.getField(TileFirepit.FIELD_FUEL_TIMER) > 0)
{
double x = rand.nextDouble() * 0.7;
double z = rand.nextDouble() * 0.7;
world.spawnParticle(EnumParticleTypes.FLAME, pos.getX()+0.15+x, pos.getY()+0.4, pos.getZ()+0.15+z, 0, 0.0, 0);
world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, pos.getX()+0.15+x, pos.getY()+0.4, pos.getZ()+0.15+z, 0, 0.02, 0);
}
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void handleFOV(FOVUpdateEvent event)
{
EntityPlayer player = event.getEntity();
// Calculate FOV based on the variable draw speed of the bow depending on player armor.
//Removed on port
/*if (player.isUsingItem() && player.getItemInUse().getItem() instanceof ItemCustomBow)
{
float fov = 1.0F;
int duration = player.getItemInUseDuration();
float speed = ItemCustomBow.getUseSpeed(player);
float force = duration / speed;
if (force > 1.0F)
{
force = 1.0F;
}
else
{
force *= force;
}
fov *= 1.0F - force * 0.15F;
event.newfov = fov;
}*/
}
@SideOnly(Side.CLIENT)
protected static List<String> getItemToolTip(ItemStack itemStack) {
Minecraft mc = Minecraft.getMinecraft();
ITooltipFlag flag = mc.gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL;
List<String> tooltip = itemStack.getTooltip(mc.player, flag);
for (int i = 0; i < tooltip.size(); ++i) {
if (i == 0) {
tooltip.set(i, itemStack.getItem().getForgeRarity(itemStack).getColor() + tooltip.get(i));
} else {
tooltip.set(i, TextFormatting.GRAY + tooltip.get(i));
}
}
return tooltip;
}